Guard extra call in ZHA lights (#47832)
* add flag to prevent sending an on command * fix condition * add constant for default transition * make groups work with new force on flag * reorder light entity creation * rearrange logic * update test * remove failed attempt at group light flag * fix flag
This commit is contained in:
parent
9647eeb2e0
commit
673ebe2911
2 changed files with 20 additions and 7 deletions
|
@ -65,6 +65,8 @@ CAPABILITIES_COLOR_LOOP = 0x4
|
||||||
CAPABILITIES_COLOR_XY = 0x08
|
CAPABILITIES_COLOR_XY = 0x08
|
||||||
CAPABILITIES_COLOR_TEMP = 0x10
|
CAPABILITIES_COLOR_TEMP = 0x10
|
||||||
|
|
||||||
|
DEFAULT_TRANSITION = 1
|
||||||
|
|
||||||
UPDATE_COLORLOOP_ACTION = 0x1
|
UPDATE_COLORLOOP_ACTION = 0x1
|
||||||
UPDATE_COLORLOOP_DIRECTION = 0x2
|
UPDATE_COLORLOOP_DIRECTION = 0x2
|
||||||
UPDATE_COLORLOOP_TIME = 0x4
|
UPDATE_COLORLOOP_TIME = 0x4
|
||||||
|
@ -114,6 +116,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
class BaseLight(LogMixin, light.LightEntity):
|
class BaseLight(LogMixin, light.LightEntity):
|
||||||
"""Operations common to all light entities."""
|
"""Operations common to all light entities."""
|
||||||
|
|
||||||
|
_FORCE_ON = False
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Initialize the light."""
|
"""Initialize the light."""
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
@ -201,7 +205,7 @@ class BaseLight(LogMixin, light.LightEntity):
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Turn the entity on."""
|
"""Turn the entity on."""
|
||||||
transition = kwargs.get(light.ATTR_TRANSITION)
|
transition = kwargs.get(light.ATTR_TRANSITION)
|
||||||
duration = transition * 10 if transition else 1
|
duration = transition * 10 if transition else DEFAULT_TRANSITION
|
||||||
brightness = kwargs.get(light.ATTR_BRIGHTNESS)
|
brightness = kwargs.get(light.ATTR_BRIGHTNESS)
|
||||||
effect = kwargs.get(light.ATTR_EFFECT)
|
effect = kwargs.get(light.ATTR_EFFECT)
|
||||||
flash = kwargs.get(light.ATTR_FLASH)
|
flash = kwargs.get(light.ATTR_FLASH)
|
||||||
|
@ -228,7 +232,7 @@ class BaseLight(LogMixin, light.LightEntity):
|
||||||
if level:
|
if level:
|
||||||
self._brightness = level
|
self._brightness = level
|
||||||
|
|
||||||
if brightness is None or brightness:
|
if brightness is None or (self._FORCE_ON and brightness):
|
||||||
# since some lights don't always turn on with move_to_level_with_on_off,
|
# since some lights don't always turn on with move_to_level_with_on_off,
|
||||||
# we should call the on command on the on_off cluster if brightness is not 0.
|
# we should call the on command on the on_off cluster if brightness is not 0.
|
||||||
result = await self._on_off_channel.on()
|
result = await self._on_off_channel.on()
|
||||||
|
@ -512,6 +516,17 @@ class HueLight(Light):
|
||||||
_REFRESH_INTERVAL = (3, 5)
|
_REFRESH_INTERVAL = (3, 5)
|
||||||
|
|
||||||
|
|
||||||
|
@STRICT_MATCH(
|
||||||
|
channel_names=CHANNEL_ON_OFF,
|
||||||
|
aux_channels={CHANNEL_COLOR, CHANNEL_LEVEL},
|
||||||
|
manufacturers="Jasco",
|
||||||
|
)
|
||||||
|
class ForceOnLight(Light):
|
||||||
|
"""Representation of a light which does not respect move_to_level_with_on_off."""
|
||||||
|
|
||||||
|
_FORCE_ON = True
|
||||||
|
|
||||||
|
|
||||||
@GROUP_MATCH()
|
@GROUP_MATCH()
|
||||||
class LightGroup(BaseLight, ZhaGroupEntity):
|
class LightGroup(BaseLight, ZhaGroupEntity):
|
||||||
"""Representation of a light group."""
|
"""Representation of a light group."""
|
||||||
|
|
|
@ -392,13 +392,11 @@ async def async_test_level_on_off_from_hass(
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
DOMAIN, "turn_on", {"entity_id": entity_id, "brightness": 10}, blocking=True
|
DOMAIN, "turn_on", {"entity_id": entity_id, "brightness": 10}, blocking=True
|
||||||
)
|
)
|
||||||
assert on_off_cluster.request.call_count == 1
|
# the onoff cluster is now not used when brightness is present by default
|
||||||
assert on_off_cluster.request.await_count == 1
|
assert on_off_cluster.request.call_count == 0
|
||||||
|
assert on_off_cluster.request.await_count == 0
|
||||||
assert level_cluster.request.call_count == 1
|
assert level_cluster.request.call_count == 1
|
||||||
assert level_cluster.request.await_count == 1
|
assert level_cluster.request.await_count == 1
|
||||||
assert on_off_cluster.request.call_args == call(
|
|
||||||
False, ON, (), expect_reply=True, manufacturer=None, tries=1, tsn=None
|
|
||||||
)
|
|
||||||
assert level_cluster.request.call_args == call(
|
assert level_cluster.request.call_args == call(
|
||||||
False,
|
False,
|
||||||
4,
|
4,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue