[avmfritz] Fixed update of data for blinds (#11773)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2021-12-15 13:53:29 +01:00 committed by GitHub
parent caa9e3500d
commit 05e782ec1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 100 additions and 14 deletions

View File

@ -91,7 +91,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
/**
* keeps track of the current state for handling of increase/decrease
*/
private @Nullable AVMFritzBaseModel state;
private AVMFritzBaseModel currentDevice = new DeviceModel();
private @Nullable String identifier;
/**
@ -130,7 +130,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Device not present");
}
state = device;
currentDevice = device;
updateProperties(device, editProperties());
@ -156,13 +156,12 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
}
if (deviceModel.isHANFUNBlinds()) {
updateLevelControl(deviceModel.getLevelControlModel());
}
if (deviceModel.isColorLight()) {
} else if (deviceModel.isColorLight()) {
updateColorLight(deviceModel.getColorControlModel(), deviceModel.getLevelControlModel());
} else if (deviceModel.isDimmableLight()) {
updateDimmableLight(deviceModel.getLevelControlModel());
} else if (device.isHANFUNUnit() && device.isHANFUNOnOff()) {
updateSimpleOnOffUnit(device.getSimpleOnOffUnit());
} else if (deviceModel.isHANFUNUnit() && deviceModel.isHANFUNOnOff()) {
updateSimpleOnOffUnit(deviceModel.getSimpleOnOffUnit());
}
}
}
@ -438,7 +437,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
((QuantityType<?>) command).getUnit(), SIUnits.CELSIUS);
}
} else if (command instanceof IncreaseDecreaseType) {
temperature = state.getHkr().getTsoll();
temperature = currentDevice.getHkr().getTsoll();
if (IncreaseDecreaseType.INCREASE.equals(command)) {
temperature.add(BigDecimal.ONE);
} else {
@ -449,7 +448,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
}
if (temperature != null) {
fritzBox.setSetTemp(ain, fromCelsius(temperature));
HeatingModel heatingModel = state.getHkr();
HeatingModel heatingModel = currentDevice.getHkr();
heatingModel.setTsoll(temperature);
updateState(CHANNEL_RADIATOR_MODE, new StringType(heatingModel.getRadiatorMode()));
}
@ -465,10 +464,10 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
targetTemperature = TEMP_FRITZ_OFF;
break;
case MODE_COMFORT:
targetTemperature = state.getHkr().getKomfort();
targetTemperature = currentDevice.getHkr().getKomfort();
break;
case MODE_ECO:
targetTemperature = state.getHkr().getAbsenk();
targetTemperature = currentDevice.getHkr().getAbsenk();
break;
case MODE_BOOST:
targetTemperature = TEMP_FRITZ_MAX;
@ -480,7 +479,7 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
}
if (targetTemperature != null) {
fritzBox.setSetTemp(ain, targetTemperature);
state.getHkr().setTsoll(targetTemperature);
currentDevice.getHkr().setTsoll(targetTemperature);
updateState(CHANNEL_SETTEMP, new QuantityType<>(toCelsius(targetTemperature), SIUnits.CELSIUS));
}
}

View File

@ -85,6 +85,30 @@ public class AVMFritzDeviceListModelTest {
+ " <unittype>262</unittype>\n"
+ " <interfaces>512</interfaces>\n"
+ " </etsiunitinfo>\n"
+ "</device>"
+ "<device identifier=\"12701 0027533-1\" id=\"2002\" functionbitmask=\"237572\" fwversion=\"0.0\" manufacturer=\"0x319d\" productname=\"HAN-FUN\">\n"
+ " <present>0</present>\n"
+ " <txbusy>0</txbusy>\n"
+ " <name>SmartHome LED-Lampe #1</name>\n"
+ " <simpleonoff>\n"
+ " <state>0</state>\n"
+ " </simpleonoff>\n"
+ " <levelcontrol>\n"
+ " <level>26</level>\n"
+ " <levelpercentage>10</levelpercentage>\n"
+ " </levelcontrol>\n"
+ " <colorcontrol supported_modes=\"0\" current_mode=\"\" fullcolorsupport=\"0\" mapped=\"0\">\n"
+ " <hue>254</hue>\n"
+ " <saturation>100</saturation>\n"
+ " <unmapped_hue></unmapped_hue>\n"
+ " <unmapped_saturation></unmapped_saturation>\n"
+ " <temperature>2700</temperature>\n"
+ " </colorcontrol>\n"
+ " <etsiunitinfo>\n"
+ " <etsideviceid>407</etsideviceid>\n"
+ " <unittype>278</unittype>\n"
+ " <interfaces>512,514,513</interfaces>\n"
+ " </etsiunitinfo>\n"
+ "</device>" +
"</devicelist>";
//@formatter:on
@ -96,7 +120,7 @@ public class AVMFritzDeviceListModelTest {
@Test
public void validateDeviceListModel() {
assertNotNull(devices);
assertEquals(16, devices.getDevicelist().size());
assertEquals(17, devices.getDevicelist().size());
assertEquals("1", devices.getXmlApiVersion());
}
@ -611,15 +635,21 @@ public class AVMFritzDeviceListModelTest {
assertEquals(1, device.getPresent());
assertEquals("Rollotron 1213 #1", device.getName());
assertFalse(device.isButton());
assertFalse(device.isHANFUNDevice());
assertFalse(device.isHANFUNButton());
assertTrue(device.isHANFUNAlarmSensor());
assertFalse(device.isDectRepeater());
assertFalse(device.isButton());
assertFalse(device.isSwitchableOutlet());
assertFalse(device.isTemperatureSensor());
assertFalse(device.isHumiditySensor());
assertFalse(device.isPowermeter());
assertFalse(device.isDectRepeater());
assertFalse(device.isHeatingThermostat());
assertFalse(device.hasMicrophone());
assertTrue(device.isHANFUNUnit());
assertTrue(device.isHANFUNOnOff());
assertTrue(device.isDimmableLight());
assertFalse(device.isColorLight());
assertTrue(device.isHANFUNBlinds());
assertTrue(device.getButtons().isEmpty());
@ -641,6 +671,63 @@ public class AVMFritzDeviceListModelTest {
assertEquals(BigDecimal.valueOf(10L), levelcontrol.getLevelPercentage());
}
@Test
public void validateHANFUNColorLightModel() {
Optional<AVMFritzBaseModel> optionalDevice = findModelByIdentifier("127010027533-1");
assertTrue(optionalDevice.isPresent());
assertTrue(optionalDevice.get() instanceof DeviceModel);
DeviceModel device = (DeviceModel) optionalDevice.get();
assertEquals("HAN-FUN", device.getProductName());
assertEquals("127010027533-1", device.getIdentifier());
assertEquals("2002", device.getDeviceId());
assertEquals("0.0", device.getFirmwareVersion());
assertEquals("0x319d", device.getManufacturer());
assertEquals(0, device.getPresent());
assertEquals("SmartHome LED-Lampe #1", device.getName());
assertFalse(device.isHANFUNDevice());
assertFalse(device.isHANFUNButton());
assertFalse(device.isHANFUNAlarmSensor());
assertFalse(device.isButton());
assertFalse(device.isSwitchableOutlet());
assertFalse(device.isTemperatureSensor());
assertFalse(device.isHumiditySensor());
assertFalse(device.isPowermeter());
assertFalse(device.isDectRepeater());
assertFalse(device.isHeatingThermostat());
assertFalse(device.hasMicrophone());
assertTrue(device.isHANFUNUnit());
assertTrue(device.isHANFUNOnOff());
assertTrue(device.isDimmableLight());
assertTrue(device.isColorLight());
assertFalse(device.isHANFUNBlinds());
assertTrue(device.getButtons().isEmpty());
assertNull(device.getAlert());
assertNull(device.getSwitch());
assertNull(device.getTemperature());
assertNull(device.getPowermeter());
assertNull(device.getHkr());
LevelControlModel levelcontrol = device.getLevelControlModel();
assertNotNull(levelcontrol);
assertEquals(BigDecimal.valueOf(26L), levelcontrol.getLevel());
assertEquals(BigDecimal.valueOf(10L), levelcontrol.getLevelPercentage());
ColorControlModel colorModel = device.getColorControlModel();
assertNotNull(colorModel);
assertEquals(254, colorModel.hue);
assertEquals(100, colorModel.saturation);
assertEquals(2700, colorModel.temperature);
}
@Test
public void validateHANFUNOnOffModel() {
Optional<AVMFritzBaseModel> optionalDevice = findModelByIdentifier("113240824499-1");