Simplify DateTimeType handling for Air Quality

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-12-10 21:09:35 +01:00 committed by lsiepel
parent e310161327
commit e3a1abd191
2 changed files with 4 additions and 14 deletions

View File

@ -21,7 +21,6 @@ import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.airquality.internal.handler.AirQualityBridgeHandler;
import org.openhab.binding.airquality.internal.handler.AirQualityStationHandler;
import org.openhab.core.i18n.LocationProvider;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
@ -43,13 +42,10 @@ import org.osgi.service.component.annotations.Reference;
public class AirQualityHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(BRIDGE_TYPE_API, THING_TYPE_STATION);
private final TimeZoneProvider timeZoneProvider;
private final LocationProvider locationProvider;
@Activate
public AirQualityHandlerFactory(final @Reference TimeZoneProvider timeZoneProvider,
final @Reference LocationProvider locationProvider) {
this.timeZoneProvider = timeZoneProvider;
public AirQualityHandlerFactory(final @Reference LocationProvider locationProvider) {
this.locationProvider = locationProvider;
}
@ -62,8 +58,7 @@ public class AirQualityHandlerFactory extends BaseThingHandlerFactory {
protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
return THING_TYPE_STATION.equals(thingTypeUID)
? new AirQualityStationHandler(thing, timeZoneProvider, locationProvider)
return THING_TYPE_STATION.equals(thingTypeUID) ? new AirQualityStationHandler(thing, locationProvider)
: BRIDGE_TYPE_API.equals(thingTypeUID) ? new AirQualityBridgeHandler((Bridge) thing) : null;
}
}

View File

@ -40,7 +40,6 @@ import org.openhab.binding.airquality.internal.config.AirQualityConfiguration;
import org.openhab.binding.airquality.internal.config.SensitiveGroupConfiguration;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.i18n.LocationProvider;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
@ -78,14 +77,12 @@ import org.slf4j.LoggerFactory;
public class AirQualityStationHandler extends BaseThingHandler {
private final @NonNullByDefault({}) ClassLoader classLoader = AirQualityStationHandler.class.getClassLoader();
private final Logger logger = LoggerFactory.getLogger(AirQualityStationHandler.class);
private final TimeZoneProvider timeZoneProvider;
private final LocationProvider locationProvider;
private @Nullable ScheduledFuture<?> refreshJob;
public AirQualityStationHandler(Thing thing, TimeZoneProvider timeZoneProvider, LocationProvider locationProvider) {
public AirQualityStationHandler(Thing thing, LocationProvider locationProvider) {
super(thing);
this.timeZoneProvider = timeZoneProvider;
this.locationProvider = locationProvider;
}
@ -263,9 +260,7 @@ public class AirQualityStationHandler extends BaseThingHandler {
return hum != -1 ? new QuantityType<>(hum, Units.PERCENT) : UnDefType.NULL;
case TIMESTAMP:
AirQualityTime time = data.getTime();
return time != null
? new DateTimeType(time.getObservationTime().withZoneSameLocal(timeZoneProvider.getTimeZone()))
: UnDefType.NULL;
return time != null ? new DateTimeType(time.getObservationTime()) : UnDefType.NULL;
case DOMINENT:
return new StringType(data.getDominentPol());
case DEW_POINT: