2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.impl;
15 import java.text.DateFormat;
16 import java.text.ParseException;
17 import java.text.SimpleDateFormat;
18 import java.util.Date;
20 import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.BaseSensorValues;
21 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 import com.google.gson.JsonObject;
28 * The {@link WeatherSensorData} acts as container for the digitalSTROM json-method <i>getSensorValues</i>. The
29 * {@link WeatherSensorData} contains all {@link CachedSensorValue}s and weather service information of the
30 * digitalSTROM-server, if a weather service is set.
32 * @author Michael Ochel - Initial contribution
33 * @author Matthias Siegele - Initial contribution
35 public class WeatherSensorData extends BaseSensorValues {
37 private final Logger logger = LoggerFactory.getLogger(WeatherSensorData.class);
39 private String weatherIconId;
40 private String weatherConditionId;
41 private String weatherServiceId;
42 private String weatherServiceTime;
45 * Creates a new {@link SensorValues} through the {@link JsonObject} that will be returned by an apartment call.
47 * @param jObject must not be null
49 public WeatherSensorData(JsonObject jObject) {
50 super.addSensorValue(jObject, true);
51 if (jObject.get(JSONApiResponseKeysEnum.WEATHER_ICON_ID.getKey()) != null) {
52 weatherIconId = jObject.get(JSONApiResponseKeysEnum.WEATHER_ICON_ID.getKey()).getAsString();
54 if (jObject.get(JSONApiResponseKeysEnum.WEATHER_CONDITION_ID.getKey()) != null) {
55 weatherConditionId = jObject.get(JSONApiResponseKeysEnum.WEATHER_CONDITION_ID.getKey()).getAsString();
57 if (jObject.get(JSONApiResponseKeysEnum.WEATHER_SERVICE_ID.getKey()) != null) {
58 weatherServiceId = jObject.get(JSONApiResponseKeysEnum.WEATHER_SERVICE_ID.getKey()).getAsString();
60 if (jObject.get(JSONApiResponseKeysEnum.WEATHER_SERVICE_TIME.getKey()) != null) {
61 weatherServiceTime = jObject.get(JSONApiResponseKeysEnum.WEATHER_SERVICE_TIME.getKey()).getAsString();
66 * Returns the weather icon id of the set weather service.
68 * @return the weatherIconId
70 public String getWeatherIconId() {
75 * Returns the weather condition id of the set weather service.
77 * @return the weatherConditionId
79 public String getWeatherConditionId() {
80 return weatherConditionId;
84 * Returns the weather service id of the set weather service.
86 * @return the weatherServiceId
88 public String getWeatherServiceId() {
89 return weatherServiceId;
93 * Returns the weather service time as {@link String} of the set weather service.
95 * @return the weatherServiceTime as {@link String}
97 public String getWeatherServiceTimeAsSting() {
98 return weatherServiceTime;
102 * Returns the weather service time as {@link Date} of the set weather service.
104 * @return the weatherServiceTime as {@link Date}
106 public Date getWeatherServiceTimeAsDate() {
107 DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SS");
109 return formatter.parse(weatherServiceTime);
110 } catch (ParseException e) {
111 logger.error("A ParseException occurred by parsing date string: {}", weatherServiceTime, e);
119 * @see java.lang.Object#toString()
122 public String toString() {
123 return "WeatherSensorData [weatherIconId=" + weatherIconId + ", weatherConditionId=" + weatherConditionId
124 + ", weatherServiceId=" + weatherServiceId + ", weatherServiceTime=" + weatherServiceTime + ", "
125 + super.toString() + "]";