Added support for HAN-FUN Color and Dimmable bulbs (#11723)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp
2021-12-07 09:32:39 +01:00
committed by GitHub
parent 4f26c65c0c
commit 95a2b333dd
10 changed files with 154 additions and 20 deletions

View File

@@ -55,6 +55,8 @@ public class AVMFritzBindingConstants {
public static final String DEVICE_HAN_FUN_SWITCH = "HAN_FUN_SWITCH";
public static final String DEVICE_HAN_FUN_ON_OFF = "HAN_FUN_ON_OFF";
public static final String DEVICE_HAN_FUN_BLINDS = "HAN_FUN_BLINDS";
public static final String DEVICE_HAN_FUN_COLOR_BULB = "HAN_FUN_COLOR_BULB";
public static final String DEVICE_HAN_FUN_DIMMABLE_BULB = "HAN_FUN_DIMMABLE_BULB";
// List of main group types
public static final String GROUP_HEATING = "FRITZ_GROUP_HEATING";
@@ -78,6 +80,10 @@ public class AVMFritzBindingConstants {
public static final ThingTypeUID HAN_FUN_SWITCH_THING_TYPE = new ThingTypeUID(BINDING_ID, DEVICE_HAN_FUN_SWITCH);
public static final ThingTypeUID HAN_FUN_ON_OFF_THING_TYPE = new ThingTypeUID(BINDING_ID, DEVICE_HAN_FUN_ON_OFF);
public static final ThingTypeUID HAN_FUN_BLINDS_THING_TYPE = new ThingTypeUID(BINDING_ID, DEVICE_HAN_FUN_BLINDS);
public static final ThingTypeUID HAN_FUN_COLOR_BULB_THING_TYPE = new ThingTypeUID(BINDING_ID,
DEVICE_HAN_FUN_COLOR_BULB);
public static final ThingTypeUID HAN_FUN_DIMMABLE_BULB_THING_TYPE = new ThingTypeUID(BINDING_ID,
DEVICE_HAN_FUN_DIMMABLE_BULB);
public static final ThingTypeUID GROUP_HEATING_THING_TYPE = new ThingTypeUID(BINDING_ID, GROUP_HEATING);
public static final ThingTypeUID GROUP_SWITCH_THING_TYPE = new ThingTypeUID(BINDING_ID, GROUP_SWITCH);
@@ -132,9 +138,9 @@ public class AVMFritzBindingConstants {
public static final String CHANNEL_PRESS = "press";
public static final String CHANNEL_LAST_CHANGE = "last_change";
public static final String CHANNEL_ROLLERSHUTTER = "rollershutter";
public static final String CHANNEL_ON_OFF = "on_off";
public static final String CHANNEL_COLOR = "color";
public static final String CHANNEL_BRIGHTNESS = "brightness";
public static final String CHANNEL_ON_OFF = "on_off";
// List of all Channel config ids
public static final String CONFIG_CHANNEL_TEMP_OFFSET = "offset";
@@ -167,7 +173,8 @@ public class AVMFritzBindingConstants {
public static final String MODE_WINDOW_OPEN = "WINDOW_OPEN";
public static final String MODE_UNKNOWN = "UNKNOWN";
public static final Set<ThingTypeUID> SUPPORTED_LIGHTING_THING_TYPES = Set.of(DECT500_THING_TYPE);
public static final Set<ThingTypeUID> SUPPORTED_LIGHTING_THING_TYPES = Set.of(DECT500_THING_TYPE,
HAN_FUN_COLOR_BULB_THING_TYPE, HAN_FUN_DIMMABLE_BULB_THING_TYPE);
public static final Set<ThingTypeUID> SUPPORTED_BUTTON_THING_TYPES_UIDS = Set.of(DECT400_THING_TYPE,
DECT440_THING_TYPE, HAN_FUN_SWITCH_THING_TYPE);

View File

@@ -17,6 +17,8 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import org.openhab.core.library.types.PercentType;
/**
* See {@link DeviceListModel}.
*
@@ -26,6 +28,8 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "colorcontrol")
public class ColorControlModel {
private static final double SATURATION_FACTOR = 2.54;
@XmlAttribute(name = "supported_modes")
public int supportedModes;
@XmlAttribute(name = "current_mode")
@@ -34,10 +38,40 @@ public class ColorControlModel {
public int saturation;
public int temperature;
/**
* Converts a FRITZ!Box value to a percent value.
*
* @param fritzValue The FRITZ!Box value to be converted
* @return The percent value
*/
public static PercentType toPercent(int saturation) {
int saturationInPercent = (int) Math.ceil(saturation / SATURATION_FACTOR);
return restrictToBounds(saturationInPercent);
}
/**
* Converts a percent value to a FRITZ!Box value.
*
* @param saturationInPercent The percent value to be converted
* @return The FRITZ!Box value
*/
public static int fromPercent(PercentType saturationInPercent) {
return (int) Math.floor(saturationInPercent.intValue() * SATURATION_FACTOR);
}
@Override
public String toString() {
return new StringBuilder("[supportedModes=").append(supportedModes).append(",currentMode=").append(currentMode)
.append(",hue=").append(hue).append(",saturation=").append(saturation).append(",temperature=")
.append(temperature).append("]").toString();
}
private static PercentType restrictToBounds(int percentValue) {
if (percentValue < 0) {
return PercentType.ZERO;
} else if (percentValue > 100) {
return PercentType.HUNDRED;
}
return new PercentType(percentValue);
}
}

View File

@@ -240,12 +240,10 @@ public class HeatingModel implements BatteryModel {
}
/**
* Converts a celsius value to a FRITZ!Box value.
* Valid celsius values: 8 to 28 °C > 16 to 56
* 16 <= 8°C, 17 = 8.5°C...... 56 >= 28°C, 254 = ON, 253 = OFF
* Converts a FRITZ!Box value to a celsius value.
*
* @param celsiusValue The celsius value to be converted
* @return The FRITZ!Box value
* @param fritzValue The FRITZ!Box value to be converted
* @return The celsius value
*/
public static BigDecimal toCelsius(BigDecimal fritzValue) {
if (fritzValue == null) {

View File

@@ -329,6 +329,10 @@ public abstract class AVMFritzBaseBridgeHandler extends BaseBridgeHandler {
} else if (device instanceof DeviceModel && device.isHANFUNUnit()) {
if (device.isHANFUNBlinds()) {
return DEVICE_HAN_FUN_BLINDS;
} else if (device.isColorLight()) {
return DEVICE_HAN_FUN_COLOR_BULB;
} else if (device.isDimmableLight()) {
return DEVICE_HAN_FUN_DIMMABLE_BULB;
}
List<String> interfaces = Arrays
.asList(((DeviceModel) device).getEtsiunitinfo().getInterfaces().split(","));

View File

@@ -143,9 +143,6 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
if (device.isHeatingThermostat()) {
updateHeatingThermostat(device.getHkr());
}
if (device.isHANFUNUnit() && device.isHANFUNOnOff()) {
updateSimpleOnOffUnit(device.getSimpleOnOffUnit());
}
if (device instanceof DeviceModel) {
DeviceModel deviceModel = (DeviceModel) device;
if (deviceModel.isTemperatureSensor()) {
@@ -164,6 +161,8 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
updateColorLight(deviceModel.getColorControlModel(), deviceModel.getLevelControlModel());
} else if (deviceModel.isDimmableLight()) {
updateDimmableLight(deviceModel.getLevelControlModel());
} else if (device.isHANFUNUnit() && device.isHANFUNOnOff()) {
updateSimpleOnOffUnit(device.getSimpleOnOffUnit());
}
}
}
@@ -208,10 +207,9 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
@Nullable LevelControlModel levelControlModel) {
if (colorControlModel != null && levelControlModel != null) {
DecimalType hue = new DecimalType(colorControlModel.hue);
PercentType saturation = new PercentType(colorControlModel.saturation);
PercentType saturation = ColorControlModel.toPercent(colorControlModel.saturation);
PercentType brightness = new PercentType(levelControlModel.getLevelPercentage());
updateThingChannelState(CHANNEL_COLOR, new HSBType(hue, saturation, brightness));
updateThingChannelState(CHANNEL_BRIGHTNESS, brightness);
}
}
@@ -414,10 +412,12 @@ public abstract class AVMFritzBaseThingHandler extends BaseThingHandler implemen
if (command instanceof HSBType) {
HSBType hsbType = (HSBType) command;
brightness = hsbType.getBrightness().toBigDecimal();
fritzBox.setHueAndSaturation(ain, hsbType.getHue().intValue(), hsbType.getSaturation().intValue(),
0);
fritzBox.setHueAndSaturation(ain, hsbType.getHue().intValue(),
ColorControlModel.fromPercent(hsbType.getSaturation()), 0);
} else if (command instanceof PercentType) {
brightness = ((PercentType) command).toBigDecimal();
} else if (command instanceof OnOffType) {
fritzBox.setSwitch(ain, OnOffType.ON.equals(command));
}
if (brightness != null) {
fritzBox.setLevelPercentage(ain, brightness);

View File

@@ -39,8 +39,12 @@ thing-type.avmfritz.FRITZ_Powerline_546E_Solo.label = FRITZ!Powerline 546E
thing-type.avmfritz.FRITZ_Powerline_546E_Solo.description = A FRITZ!Powerline 546E with switchable outlet in stand-alone mode.
thing-type.avmfritz.HAN_FUN_BLINDS.label = HAN-FUN Blinds
thing-type.avmfritz.HAN_FUN_BLINDS.description = HAN-FUN blinds (e.g. RolloTron DECT 1213)
thing-type.avmfritz.HAN_FUN_COLOR_BULB.label = HAN-FUN Color Light
thing-type.avmfritz.HAN_FUN_COLOR_BULB.description = HAN-FUN color light (e.g SmartHome LED-Lampe E27 (farbig)).
thing-type.avmfritz.HAN_FUN_CONTACT.label = HAN-FUN Contact
thing-type.avmfritz.HAN_FUN_CONTACT.description = HAN-FUN contact (e.g. SmartHome Tür-/Fensterkontakt or SmartHome Bewegungsmelder).
thing-type.avmfritz.HAN_FUN_DIMMABLE_BULB.label = HAN-FUN Dimmable Light
thing-type.avmfritz.HAN_FUN_DIMMABLE_BULB.description = HAN-FUN dimmable light (e.g. SmartHome LED-Lampe E27 (warmweiß)).
thing-type.avmfritz.HAN_FUN_ON_OFF.label = HAN-FUN On / Off Device
thing-type.avmfritz.HAN_FUN_ON_OFF.description = HAN-FUN switchable device (e.g. SmartHome Zwischenstecker innen / SmartHome Zwischenstecker außen)
thing-type.avmfritz.HAN_FUN_SWITCH.label = HAN-FUN Switch

View File

@@ -14,8 +14,6 @@
<description>FRITZ!DECT500 color light.</description>
<channels>
<channel id="onoffstate" typeId="system.power"/>
<channel id="brightness" typeId="system.brightness"/>
<channel id="color" typeId="system.color"/>
</channels>
@@ -314,6 +312,41 @@
<config-description-ref uri="thing-type:avmfritz:fritzdevice"/>
</thing-type>
<thing-type id="HAN_FUN_COLOR_BULB">
<supported-bridge-type-refs>
<bridge-type-ref id="fritzbox"/>
</supported-bridge-type-refs>
<label>HAN-FUN Color Light</label>
<description>HAN-FUN color light (e.g SmartHome LED-Lampe E27 (farbig)).</description>
<channels>
<channel id="color" typeId="system.color"/>
</channels>
<representation-property>ain</representation-property>
<config-description-ref uri="thing-type:avmfritz:fritzdevice"/>
</thing-type>
<thing-type id="HAN_FUN_DIMMABLE_BULB">
<supported-bridge-type-refs>
<bridge-type-ref id="fritzbox"/>
</supported-bridge-type-refs>
<label>HAN-FUN Dimmable Light</label>
<description>HAN-FUN dimmable light (e.g. SmartHome LED-Lampe E27 (warmweiß)).</description>
<channels>
<channel id="brightness" typeId="system.brightness"/>
</channels>
<representation-property>ain</representation-property>
<config-description-ref uri="thing-type:avmfritz:fritzdevice"/>
</thing-type>
<thing-type id="HAN_FUN_ON_OFF">
<supported-bridge-type-refs>
<bridge-type-ref id="fritzbox"/>