mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 04:05:20 +01:00
Fix color temperature attributes in wiz (#161125)
This commit is contained in:
@@ -80,6 +80,9 @@ class WizBulbEntity(WizToggleEntity, LightEntity):
|
|||||||
color_modes.add(RGB_WHITE_CHANNELS_COLOR_MODE[bulb_type.white_channels])
|
color_modes.add(RGB_WHITE_CHANNELS_COLOR_MODE[bulb_type.white_channels])
|
||||||
if features.color_tmp:
|
if features.color_tmp:
|
||||||
color_modes.add(ColorMode.COLOR_TEMP)
|
color_modes.add(ColorMode.COLOR_TEMP)
|
||||||
|
kelvin = bulb_type.kelvin_range
|
||||||
|
self._attr_max_color_temp_kelvin = kelvin.max
|
||||||
|
self._attr_min_color_temp_kelvin = kelvin.min
|
||||||
if features.brightness:
|
if features.brightness:
|
||||||
color_modes.add(ColorMode.BRIGHTNESS)
|
color_modes.add(ColorMode.BRIGHTNESS)
|
||||||
self._attr_supported_color_modes = filter_supported_color_modes(color_modes)
|
self._attr_supported_color_modes = filter_supported_color_modes(color_modes)
|
||||||
@@ -87,10 +90,6 @@ class WizBulbEntity(WizToggleEntity, LightEntity):
|
|||||||
# If the light supports only a single color mode, set it now
|
# If the light supports only a single color mode, set it now
|
||||||
self._attr_color_mode = next(iter(self._attr_supported_color_modes))
|
self._attr_color_mode = next(iter(self._attr_supported_color_modes))
|
||||||
self._attr_effect_list = wiz_data.scenes
|
self._attr_effect_list = wiz_data.scenes
|
||||||
if bulb_type.bulb_type != BulbClass.DW:
|
|
||||||
kelvin = bulb_type.kelvin_range
|
|
||||||
self._attr_max_color_temp_kelvin = kelvin.max
|
|
||||||
self._attr_min_color_temp_kelvin = kelvin.min
|
|
||||||
if bulb_type.features.effect:
|
if bulb_type.features.effect:
|
||||||
self._attr_supported_features = LightEntityFeature.EFFECT
|
self._attr_supported_features = LightEntityFeature.EFFECT
|
||||||
self._async_update_attrs()
|
self._async_update_attrs()
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ FAKE_DIMMABLE_FAN = BulbType(
|
|||||||
features=Features(
|
features=Features(
|
||||||
color=False,
|
color=False,
|
||||||
color_tmp=False,
|
color_tmp=False,
|
||||||
effect=True,
|
effect=False,
|
||||||
brightness=True,
|
brightness=True,
|
||||||
dual_head=False,
|
dual_head=False,
|
||||||
fan=True,
|
fan=True,
|
||||||
@@ -191,11 +191,30 @@ FAKE_DIMMABLE_FAN = BulbType(
|
|||||||
fan_reverse=True,
|
fan_reverse=True,
|
||||||
),
|
),
|
||||||
kelvin_range=KelvinRange(max=2700, min=2700),
|
kelvin_range=KelvinRange(max=2700, min=2700),
|
||||||
fw_version="1.31.32",
|
fw_version="1.34.1",
|
||||||
white_channels=1,
|
white_channels=1,
|
||||||
white_to_color_ratio=20,
|
white_to_color_ratio=20,
|
||||||
fan_speed_range=6,
|
fan_speed_range=6,
|
||||||
)
|
)
|
||||||
|
FAKE_DIMMABLE_FAN_2 = BulbType(
|
||||||
|
bulb_type=BulbClass.FANDIM,
|
||||||
|
name="ESP20_FANDIMS_31",
|
||||||
|
features=Features(
|
||||||
|
color=False,
|
||||||
|
color_tmp=False,
|
||||||
|
effect=False,
|
||||||
|
brightness=True,
|
||||||
|
dual_head=False,
|
||||||
|
fan=True,
|
||||||
|
fan_breeze_mode=True,
|
||||||
|
fan_reverse=True,
|
||||||
|
),
|
||||||
|
kelvin_range=None,
|
||||||
|
fw_version="1.34.0",
|
||||||
|
white_channels=None,
|
||||||
|
white_to_color_ratio=None,
|
||||||
|
fan_speed_range=6,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def setup_integration(hass: HomeAssistant) -> MockConfigEntry:
|
async def setup_integration(hass: HomeAssistant) -> MockConfigEntry:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
# name: test_entity[fan.mock_title-entry]
|
# name: test_entity[bulb_type0][fan.mock_title-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
}),
|
}),
|
||||||
@@ -39,7 +39,68 @@
|
|||||||
'unit_of_measurement': None,
|
'unit_of_measurement': None,
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_entity[fan.mock_title-state]
|
# name: test_entity[bulb_type0][fan.mock_title-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'direction': 'forward',
|
||||||
|
'friendly_name': 'Mock Title',
|
||||||
|
'percentage': 16,
|
||||||
|
'percentage_step': 16.666666666666668,
|
||||||
|
'preset_mode': None,
|
||||||
|
'preset_modes': list([
|
||||||
|
'breeze',
|
||||||
|
]),
|
||||||
|
'supported_features': <FanEntityFeature: 61>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'fan.mock_title',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'off',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_entity[bulb_type1][fan.mock_title-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': dict({
|
||||||
|
'preset_modes': list([
|
||||||
|
'breeze',
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'fan',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'fan.mock_title',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'object_id_base': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': None,
|
||||||
|
'platform': 'wiz',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'suggested_object_id': None,
|
||||||
|
'supported_features': <FanEntityFeature: 61>,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': 'abcabcabcabc',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_entity[bulb_type1][fan.mock_title-state]
|
||||||
StateSnapshot({
|
StateSnapshot({
|
||||||
'attributes': ReadOnlyDict({
|
'attributes': ReadOnlyDict({
|
||||||
'direction': 'forward',
|
'direction': 'forward',
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from pywizlight import BulbType
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.fan import (
|
from homeassistant.components.fan import (
|
||||||
@@ -28,7 +30,13 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from . import FAKE_DIMMABLE_FAN, FAKE_MAC, async_push_update, async_setup_integration
|
from . import (
|
||||||
|
FAKE_DIMMABLE_FAN,
|
||||||
|
FAKE_DIMMABLE_FAN_2,
|
||||||
|
FAKE_MAC,
|
||||||
|
async_push_update,
|
||||||
|
async_setup_integration,
|
||||||
|
)
|
||||||
|
|
||||||
from tests.common import snapshot_platform
|
from tests.common import snapshot_platform
|
||||||
|
|
||||||
@@ -43,12 +51,16 @@ INITIAL_PARAMS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("bulb_type", [FAKE_DIMMABLE_FAN, FAKE_DIMMABLE_FAN_2])
|
||||||
@patch("homeassistant.components.wiz.PLATFORMS", [Platform.FAN])
|
@patch("homeassistant.components.wiz.PLATFORMS", [Platform.FAN])
|
||||||
async def test_entity(
|
async def test_entity(
|
||||||
hass: HomeAssistant, snapshot: SnapshotAssertion, entity_registry: er.EntityRegistry
|
hass: HomeAssistant,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
bulb_type: BulbType,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the fan entity."""
|
"""Test the fan entity."""
|
||||||
entry = (await async_setup_integration(hass, bulb_type=FAKE_DIMMABLE_FAN))[1]
|
entry = (await async_setup_integration(hass, bulb_type=bulb_type))[1]
|
||||||
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user