moroen / IKEA-Tradfri-plugin

A Python plugin for Domoticz to controll IKEA Gateway
68 stars 23 forks source link

Setting a dimlevel of 1 (out of 254) causes domoticz to show the lights as "off" #144

Open basrieter opened 5 months ago

basrieter commented 5 months ago

Recently I noticed that I could set the dimmers of lights to a value of 1 (out of 254). This causes the plugin to round the dim level to 0 and thus making Domoticz think they are switched off.

Changing the dimmer section in plugin.py to this fixes the problem:

# Dimmer
if ikea_device.Level is not None:
    if override_level is None:
        # The remote can make the dimmer value 1 (out of 254) resulting in 0 as level.
        level_number = int(round_half_up(ikea_device.Level / 2.54)) or 1
        level = str(level_number)
    else:
        level = override_level

    if (Devices[Unit].nValue != ikea_device.State) or (
        Devices[Unit].sValue != str(level)
    ):
        Devices[Unit].Update(
            nValue=2 if ikea_device.State else 0, sValue=str(level)
        )