mirror of
https://github.com/home-assistant/core
synced 2024-09-09 12:51:22 +02:00
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
@ -65,6 +65,8 @@ CAPABILITIES_COLOR_LOOP = 0x4
|
||||
CAPABILITIES_COLOR_XY = 0x08
|
||||
CAPABILITIES_COLOR_TEMP = 0x10
|
||||
|
||||
DEFAULT_TRANSITION = 1
|
||||
|
||||
UPDATE_COLORLOOP_ACTION = 0x1
|
||||
UPDATE_COLORLOOP_DIRECTION = 0x2
|
||||
UPDATE_COLORLOOP_TIME = 0x4
|
||||
@ -114,6 +116,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
class BaseLight(LogMixin, light.LightEntity):
|
||||
"""Operations common to all light entities."""
|
||||
|
||||
_FORCE_ON = False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Initialize the light."""
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -201,7 +205,7 @@ class BaseLight(LogMixin, light.LightEntity):
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn the entity on."""
|
||||
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)
|
||||
effect = kwargs.get(light.ATTR_EFFECT)
|
||||
flash = kwargs.get(light.ATTR_FLASH)
|
||||
@ -228,7 +232,7 @@ class BaseLight(LogMixin, light.LightEntity):
|
||||
if 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,
|
||||
# we should call the on command on the on_off cluster if brightness is not 0.
|
||||
result = await self._on_off_channel.on()
|
||||
@ -512,6 +516,17 @@ class HueLight(Light):
|
||||
_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()
|
||||
class LightGroup(BaseLight, ZhaGroupEntity):
|
||||
"""Representation of a light group."""
|
||||
|
@ -392,13 +392,11 @@ async def async_test_level_on_off_from_hass(
|
||||
await hass.services.async_call(
|
||||
DOMAIN, "turn_on", {"entity_id": entity_id, "brightness": 10}, blocking=True
|
||||
)
|
||||
assert on_off_cluster.request.call_count == 1
|
||||
assert on_off_cluster.request.await_count == 1
|
||||
# the onoff cluster is now not used when brightness is present by default
|
||||
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.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(
|
||||
False,
|
||||
4,
|
||||
|
Loading…
Reference in New Issue
Block a user