Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 21 additions & 3 deletions homeassistant/components/zha/core/channels/lighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def __init__(
"""Initialize ColorChannel."""
super().__init__(cluster, ch_pool)
self._color_capabilities = None
self._min_mireds = None
Comment thread
dmulcahey marked this conversation as resolved.
Outdated
self._max_mireds = None

@property
def min_mireds(self):
"""Return the coldest color_temp that this channel supports."""
return self._min_mireds

@property
def max_mireds(self):
"""Return the warmest color_temp that this channel supports."""
return self._max_mireds

def get_color_capabilities(self):
"""Return the color capabilities."""
Expand All @@ -59,9 +71,15 @@ async def async_initialize(self, from_cache):

async def fetch_color_capabilities(self, from_cache):
"""Get the color configuration."""
capabilities = await self.get_attribute_value(
"color_capabilities", from_cache=from_cache
)
attributes = [
"color_temp_physical_min",
"color_temp_physical_max",
"color_capabilities",
]
results = await self.get_attributes(attributes, from_cache=from_cache)
capabilities = results.get("color_capabilities")
self._min_mireds = results.get("color_temp_physical_min", 153)
self._max_mireds = results.get("color_temp_physical_max", 500)

if capabilities is None:
# ZCL Version 4 devices don't support the color_capabilities
Expand Down
17 changes: 15 additions & 2 deletions homeassistant/components/zha/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self, *args, **kwargs):
self._off_brightness: Optional[int] = None
self._hs_color: Optional[Tuple[float, float]] = None
self._color_temp: Optional[int] = None
self._min_mireds: Optional[int] = 154
self._min_mireds: Optional[int] = 153
self._max_mireds: Optional[int] = 500
self._white_value: Optional[int] = None
self._effect_list: Optional[List[str]] = None
Expand Down Expand Up @@ -138,6 +138,16 @@ def brightness(self):
"""Return the brightness of this light."""
return self._brightness

@property
def min_mireds(self):
"""Return the coldest color_temp that this light supports."""
return self._min_mireds

@property
def max_mireds(self):
"""Return the warmest color_temp that this light supports."""
return self._max_mireds

def set_level(self, value):
"""Set the brightness of this light between 0..254.

Expand Down Expand Up @@ -316,6 +326,9 @@ def __init__(self, unique_id, zha_device: ZhaDeviceType, channels, **kwargs):
self._level_channel = self.cluster_channels.get(CHANNEL_LEVEL)
self._color_channel = self.cluster_channels.get(CHANNEL_COLOR)
self._identify_channel = self.zha_device.channels.identify_ch
if self._color_channel:
self._min_mireds: Optional[int] = self._color_channel.min_mireds
self._max_mireds: Optional[int] = self._color_channel.max_mireds
self._cancel_refresh_handle = None
effect_list = []

Expand Down Expand Up @@ -501,7 +514,7 @@ async def async_update(self) -> None:

self._color_temp = helpers.reduce_attribute(on_states, ATTR_COLOR_TEMP)
self._min_mireds = helpers.reduce_attribute(
states, ATTR_MIN_MIREDS, default=154, reduce=min
states, ATTR_MIN_MIREDS, default=153, reduce=min
)
self._max_mireds = helpers.reduce_attribute(
states, ATTR_MAX_MIREDS, default=500, reduce=max
Expand Down
9 changes: 9 additions & 0 deletions tests/components/zha/test_discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,12 @@ async def test_device_override(hass, zigpy_device_mock, setup_zha, override, ent
await zha_gateway.async_device_initialized(zigpy_device)
await hass.async_block_till_done()
assert hass.states.get(entity_id) is not None


async def test_group_probe_cleanup_called(hass, setup_zha, config_entry):
"""Test cleanup happens when zha is unloaded."""
await setup_zha()
disc.GROUP_PROBE.cleanup = mock.Mock(wraps=disc.GROUP_PROBE.cleanup)
await config_entry.async_unload(hass)
await hass.async_block_till_done()
disc.GROUP_PROBE.cleanup.assert_called()
9 changes: 9 additions & 0 deletions tests/components/zha/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,15 @@ async def async_test_zha_group_light_entity(
await dev3_cluster_on_off.on()
assert hass.states.get(entity_id).state == STATE_ON

# add a 3rd member and ensure we still have an entity and we track the new one
await dev1_cluster_on_off.off()
await dev3_cluster_on_off.off()
assert hass.states.get(entity_id).state == STATE_OFF
# this will test that _reprobe_group is used correctly
await zha_group.async_add_members([device_light_2.ieee])
await dev2_cluster_on_off.on()
assert hass.states.get(entity_id).state == STATE_ON

# remove the group and ensure that there is no entity and that the entity registry is cleaned up
assert zha_gateway.ha_entity_registry.async_get(entity_id) is not None
await zha_gateway.async_remove_zigpy_group(zha_group.group_id)
Expand Down