mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[bticinosmarter] Fix activationdate parsing (#15474)
* Fix DateTime format * Switch to TimeZoneProvider Signed-off-by: lsiepel <leosiepel@gmail.com>
This commit is contained in:
parent
d1a691498a
commit
d9235da5db
@ -24,6 +24,7 @@ import org.openhab.binding.bticinosmarther.internal.api.dto.Enums.LoadState;
|
||||
import org.openhab.binding.bticinosmarther.internal.api.dto.Enums.MeasureUnit;
|
||||
import org.openhab.binding.bticinosmarther.internal.api.exception.SmartherIllegalPropertyValueException;
|
||||
import org.openhab.binding.bticinosmarther.internal.util.DateUtil;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
@ -146,12 +147,16 @@ public class Chronothermostat {
|
||||
* @return a string containing the module operational activation time label, or {@code null} if the activation time
|
||||
* cannot be parsed to a valid date/time
|
||||
*/
|
||||
public @Nullable String getActivationTimeLabel() {
|
||||
public @Nullable String getActivationTimeLabel(TimeZoneProvider timeZoneProvider) {
|
||||
String timeLabel = TIME_FOREVER;
|
||||
if (activationTime != null) {
|
||||
try {
|
||||
final ZonedDateTime dateActivationTime = DateUtil.parseZonedTime(activationTime, DTF_DATETIME_EXT);
|
||||
final ZonedDateTime dateTomorrow = DateUtil.getZonedStartOfDay(1, dateActivationTime.getZone());
|
||||
boolean dateActivationTimeIsZoned = activationTime.length() > 19;
|
||||
|
||||
final ZonedDateTime dateActivationTime = DateUtil.parseZonedTime(activationTime,
|
||||
dateActivationTimeIsZoned ? DTF_DATETIME_EXT : DTF_DATETIME);
|
||||
final ZonedDateTime dateTomorrow = DateUtil.getZonedStartOfDay(1,
|
||||
dateActivationTimeIsZoned ? dateActivationTime.getZone() : timeZoneProvider.getTimeZone());
|
||||
|
||||
if (dateActivationTime.isBefore(dateTomorrow)) {
|
||||
timeLabel = DateUtil.format(dateActivationTime, DTF_TODAY);
|
||||
|
@ -21,6 +21,7 @@ import org.openhab.binding.bticinosmarther.internal.handler.SmartherBridgeHandle
|
||||
import org.openhab.binding.bticinosmarther.internal.handler.SmartherDynamicStateDescriptionProvider;
|
||||
import org.openhab.binding.bticinosmarther.internal.handler.SmartherModuleHandler;
|
||||
import org.openhab.core.auth.client.oauth2.OAuthFactory;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.io.net.http.HttpClientFactory;
|
||||
import org.openhab.core.scheduler.CronScheduler;
|
||||
import org.openhab.core.thing.Bridge;
|
||||
@ -51,16 +52,19 @@ public class SmartherHandlerFactory extends BaseThingHandlerFactory {
|
||||
private final HttpClient httpClient;
|
||||
private final CronScheduler cronScheduler;
|
||||
private final SmartherDynamicStateDescriptionProvider dynamicStateDescriptionProvider;
|
||||
private final TimeZoneProvider timeZoneProvider;
|
||||
|
||||
@Activate
|
||||
public SmartherHandlerFactory(@Reference OAuthFactory oAuthFactory, @Reference SmartherAccountService authService,
|
||||
@Reference HttpClientFactory httpClientFactory, @Reference CronScheduler cronScheduler,
|
||||
@Reference SmartherDynamicStateDescriptionProvider dynamicStateDescriptionProvider) {
|
||||
@Reference SmartherDynamicStateDescriptionProvider dynamicStateDescriptionProvider,
|
||||
final @Reference TimeZoneProvider timeZoneProvider) {
|
||||
this.oAuthFactory = oAuthFactory;
|
||||
this.authService = authService;
|
||||
this.httpClient = httpClientFactory.getCommonHttpClient();
|
||||
this.cronScheduler = cronScheduler;
|
||||
this.dynamicStateDescriptionProvider = dynamicStateDescriptionProvider;
|
||||
this.timeZoneProvider = timeZoneProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -77,7 +81,7 @@ public class SmartherHandlerFactory extends BaseThingHandlerFactory {
|
||||
this.authService.addSmartherAccountHandler(handler);
|
||||
return handler;
|
||||
} else if (SmartherBindingConstants.THING_TYPE_MODULE.equals(thingTypeUID)) {
|
||||
return new SmartherModuleHandler(thing, cronScheduler, dynamicStateDescriptionProvider);
|
||||
return new SmartherModuleHandler(thing, cronScheduler, dynamicStateDescriptionProvider, timeZoneProvider);
|
||||
} else {
|
||||
logger.debug("Unsupported thing {}", thing.getThingTypeUID());
|
||||
return null;
|
||||
|
@ -34,6 +34,7 @@ import org.openhab.binding.bticinosmarther.internal.config.SmartherModuleConfigu
|
||||
import org.openhab.binding.bticinosmarther.internal.model.ModuleSettings;
|
||||
import org.openhab.binding.bticinosmarther.internal.util.StringUtil;
|
||||
import org.openhab.core.cache.ExpiringCache;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
@ -74,6 +75,7 @@ public class SmartherModuleHandler extends BaseThingHandler {
|
||||
private final SmartherDynamicStateDescriptionProvider dynamicStateDescriptionProvider;
|
||||
private final ChannelUID programChannelUID;
|
||||
private final ChannelUID endDateChannelUID;
|
||||
private final TimeZoneProvider timeZoneProvider;
|
||||
|
||||
// Module configuration
|
||||
private SmartherModuleConfiguration config;
|
||||
@ -98,11 +100,12 @@ public class SmartherModuleHandler extends BaseThingHandler {
|
||||
* @param provider
|
||||
* the {@link SmartherDynamicStateDescriptionProvider} dynamic state description provider to be used
|
||||
*/
|
||||
public SmartherModuleHandler(Thing thing, CronScheduler scheduler,
|
||||
SmartherDynamicStateDescriptionProvider provider) {
|
||||
public SmartherModuleHandler(Thing thing, CronScheduler scheduler, SmartherDynamicStateDescriptionProvider provider,
|
||||
final TimeZoneProvider timeZoneProvider) {
|
||||
super(thing);
|
||||
this.cronScheduler = scheduler;
|
||||
this.dynamicStateDescriptionProvider = provider;
|
||||
this.timeZoneProvider = timeZoneProvider;
|
||||
this.programChannelUID = new ChannelUID(thing.getUID(), CHANNEL_SETTINGS_PROGRAM);
|
||||
this.endDateChannelUID = new ChannelUID(thing.getUID(), CHANNEL_SETTINGS_ENDDATE);
|
||||
this.config = new SmartherModuleConfiguration();
|
||||
@ -710,7 +713,8 @@ public class SmartherModuleHandler extends BaseThingHandler {
|
||||
updateChannelState(CHANNEL_STATUS_MODE,
|
||||
new StringType(StringUtil.capitalize(localChrono.getMode().toLowerCase())));
|
||||
updateChannelState(CHANNEL_STATUS_TEMPERATURE, localChrono.getSetPointTemperature().toState());
|
||||
updateChannelState(CHANNEL_STATUS_ENDTIME, new StringType(localChrono.getActivationTimeLabel()));
|
||||
updateChannelState(CHANNEL_STATUS_ENDTIME,
|
||||
new StringType(localChrono.getActivationTimeLabel(timeZoneProvider)));
|
||||
updateChannelState(CHANNEL_STATUS_TEMP_FORMAT, new StringType(localChrono.getTemperatureFormat()));
|
||||
final Program localProgram = localChrono.getProgram();
|
||||
if (localProgram != null) {
|
||||
|
Loading…
Reference in New Issue
Block a user