Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[avmfritz] Fixed update of data for blinds #11773

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ public void onDeviceUpdated(ThingUID thingUID, AVMFritzBaseModel device) {
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Device not present");
}
state = device;
currentDevice = device;

updateProperties(device, editProperties());

Expand All @@ -156,13 +156,12 @@ public void onDeviceUpdated(ThingUID thingUID, AVMFritzBaseModel device) {
}
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());
}
}
}
Expand Down Expand Up @@ -438,7 +437,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
((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 {
Expand All @@ -449,7 +448,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
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()));
}
Expand All @@ -465,10 +464,10 @@ public void handleCommand(ChannelUID channelUID, Command command) {
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;
Expand All @@ -480,7 +479,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
}
if (targetTemperature != null) {
fritzBox.setSetTemp(ain, targetTemperature);
state.getHkr().setTsoll(targetTemperature);
currentDevice.getHkr().setTsoll(targetTemperature);
updateState(CHANNEL_SETTEMP, new QuantityType<>(toCelsius(targetTemperature), SIUnits.CELSIUS));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,30 @@ public void setUp() throws JAXBException, XMLStreamException {
+ " <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
Expand All @@ -96,7 +120,7 @@ public void setUp() throws JAXBException, XMLStreamException {
@Test
public void validateDeviceListModel() {
assertNotNull(devices);
assertEquals(16, devices.getDevicelist().size());
assertEquals(17, devices.getDevicelist().size());
assertEquals("1", devices.getXmlApiVersion());
}

Expand Down Expand Up @@ -611,15 +635,21 @@ public void validateHANFUNBlindModel() {
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());
Expand All @@ -641,6 +671,63 @@ public void validateHANFUNBlindModel() {
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");
Expand Down