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
30 * {@link org.openhab.binding.digitalstrom.internal.lib.climate.datatypes.CachedSensorValue}s and weather service
31 * information of the digitalSTROM-server, if a weather service is set.
33 * @author Michael Ochel - Initial contribution
34 * @author Matthias Siegele - Initial contribution
36 public class WeatherSensorData extends BaseSensorValues {
38 private final Logger logger = LoggerFactory.getLogger(WeatherSensorData.class);
40 private String weatherIconId;
41 private String weatherConditionId;
42 private String weatherServiceId;
43 private String weatherServiceTime;
46 * Creates a new {@link SensorValues} through the {@link JsonObject} that will be returned by an apartment call.
48 * @param jObject must not be null
50 public WeatherSensorData(JsonObject jObject) {
51 super.addSensorValue(jObject, true);
52 if (jObject.get(JSONApiResponseKeysEnum.WEATHER_ICON_ID.getKey()) != null) {
53 weatherIconId = jObject.get(JSONApiResponseKeysEnum.WEATHER_ICON_ID.getKey()).getAsString();
55 if (jObject.get(JSONApiResponseKeysEnum.WEATHER_CONDITION_ID.getKey()) != null) {
56 weatherConditionId = jObject.get(JSONApiResponseKeysEnum.WEATHER_CONDITION_ID.getKey()).getAsString();
58 if (jObject.get(JSONApiResponseKeysEnum.WEATHER_SERVICE_ID.getKey()) != null) {
59 weatherServiceId = jObject.get(JSONApiResponseKeysEnum.WEATHER_SERVICE_ID.getKey()).getAsString();
61 if (jObject.get(JSONApiResponseKeysEnum.WEATHER_SERVICE_TIME.getKey()) != null) {
62 weatherServiceTime = jObject.get(JSONApiResponseKeysEnum.WEATHER_SERVICE_TIME.getKey()).getAsString();
67 * Returns the weather icon id of the set weather service.
69 * @return the weatherIconId
71 public String getWeatherIconId() {
76 * Returns the weather condition id of the set weather service.
78 * @return the weatherConditionId
80 public String getWeatherConditionId() {
81 return weatherConditionId;
85 * Returns the weather service id of the set weather service.
87 * @return the weatherServiceId
89 public String getWeatherServiceId() {
90 return weatherServiceId;
94 * Returns the weather service time as {@link String} of the set weather service.
96 * @return the weatherServiceTime as {@link String}
98 public String getWeatherServiceTimeAsSting() {
99 return weatherServiceTime;
103 * Returns the weather service time as {@link Date} of the set weather service.
105 * @return the weatherServiceTime as {@link Date}
107 public Date getWeatherServiceTimeAsDate() {
108 DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SS");
110 return formatter.parse(weatherServiceTime);
111 } catch (ParseException e) {
112 logger.error("A ParseException occurred by parsing date string: {}", weatherServiceTime, e);
120 * @see java.lang.Object#toString()
123 public String toString() {
124 return "WeatherSensorData [weatherIconId=" + weatherIconId + ", weatherConditionId=" + weatherConditionId
125 + ", weatherServiceId=" + weatherServiceId + ", weatherServiceTime=" + weatherServiceTime + ", "
126 + super.toString() + "]";