diff --git a/homeassistant/components/wiz/config_flow.py b/homeassistant/components/wiz/config_flow.py index 924e88793e4..7d86502784c 100644 --- a/homeassistant/components/wiz/config_flow.py +++ b/homeassistant/components/wiz/config_flow.py @@ -71,6 +71,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): try: bulbtype = await bulb.get_bulbtype() except WIZ_CONNECT_EXCEPTIONS as ex: + _LOGGER.debug( + "Failed to connect to %s during discovery: %s", + device.ip_address, + ex, + exc_info=True, + ) raise AbortFlow("cannot_connect") from ex self._name = name_from_bulb_type_and_mac(bulbtype, device.mac_address) diff --git a/homeassistant/components/wiz/entity.py b/homeassistant/components/wiz/entity.py index 82f19a61002..9b22d35de7d 100644 --- a/homeassistant/components/wiz/entity.py +++ b/homeassistant/components/wiz/entity.py @@ -6,6 +6,7 @@ from typing import Any from pywizlight.bulblibrary import BulbType +from homeassistant.const import ATTR_HW_VERSION, ATTR_MODEL from homeassistant.core import callback from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC from homeassistant.helpers.entity import DeviceInfo, Entity, ToggleEntity @@ -24,17 +25,20 @@ class WizEntity(CoordinatorEntity, Entity): bulb_type: BulbType = self._device.bulbtype self._attr_unique_id = self._device.mac self._attr_name = name - hw_data = bulb_type.name.split("_") - board = hw_data.pop(0) - model = hw_data.pop(0) self._attr_device_info = DeviceInfo( connections={(CONNECTION_NETWORK_MAC, self._device.mac)}, name=name, manufacturer="WiZ", - model=model, - hw_version=f"{board} {hw_data[0]}" if hw_data else board, sw_version=bulb_type.fw_version, ) + if bulb_type.name is None: + return + hw_data = bulb_type.name.split("_") + board = hw_data.pop(0) + model = hw_data.pop(0) + hw_version = f"{board} {hw_data[0]}" if hw_data else board + self._attr_device_info[ATTR_HW_VERSION] = hw_version + self._attr_device_info[ATTR_MODEL] = model @callback def _handle_coordinator_update(self) -> None: diff --git a/homeassistant/components/wiz/manifest.json b/homeassistant/components/wiz/manifest.json index 2dacb32c094..df780d7b39c 100644 --- a/homeassistant/components/wiz/manifest.json +++ b/homeassistant/components/wiz/manifest.json @@ -13,7 +13,7 @@ "dependencies": ["network"], "quality_scale": "platinum", "documentation": "https://www.home-assistant.io/integrations/wiz", - "requirements": ["pywizlight==0.5.11"], + "requirements": ["pywizlight==0.5.12"], "iot_class": "local_push", "codeowners": ["@sbidy"] } diff --git a/requirements_all.txt b/requirements_all.txt index c6c0267de34..1d3e91cd65d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2057,7 +2057,7 @@ pywemo==0.7.0 pywilight==0.0.70 # homeassistant.components.wiz -pywizlight==0.5.11 +pywizlight==0.5.12 # homeassistant.components.xeoma pyxeoma==1.4.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f82e28776c0..1ad42575a89 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1288,7 +1288,7 @@ pywemo==0.7.0 pywilight==0.0.70 # homeassistant.components.wiz -pywizlight==0.5.11 +pywizlight==0.5.12 # homeassistant.components.zerproc pyzerproc==0.4.8 diff --git a/tests/components/wiz/__init__.py b/tests/components/wiz/__init__.py index cb23b3eef34..c4a31b0a394 100644 --- a/tests/components/wiz/__init__.py +++ b/tests/components/wiz/__init__.py @@ -150,6 +150,17 @@ FAKE_SOCKET = BulbType( white_channels=2, white_to_color_ratio=80, ) +FAKE_OLD_FIRMWARE_DIMMABLE_BULB = BulbType( + bulb_type=BulbClass.DW, + name=None, + features=Features( + color=False, color_tmp=False, effect=True, brightness=True, dual_head=False + ), + kelvin_range=None, + fw_version="1.8.0", + white_channels=1, + white_to_color_ratio=80, +) async def setup_integration( diff --git a/tests/components/wiz/test_light.py b/tests/components/wiz/test_light.py index c79cf74e130..48166e941d4 100644 --- a/tests/components/wiz/test_light.py +++ b/tests/components/wiz/test_light.py @@ -22,6 +22,7 @@ from homeassistant.helpers import entity_registry as er from . import ( FAKE_MAC, + FAKE_OLD_FIRMWARE_DIMMABLE_BULB, FAKE_RGBW_BULB, FAKE_RGBWW_BULB, FAKE_TURNABLE_BULB, @@ -169,3 +170,34 @@ async def test_turnable_light(hass: HomeAssistant) -> None: state = hass.states.get(entity_id) assert state.state == STATE_ON assert state.attributes[ATTR_COLOR_TEMP] == 153 + + +async def test_old_firmware_dimmable_light(hass: HomeAssistant) -> None: + """Test a light operation with a dimmable light with old firmware.""" + bulb, _ = await async_setup_integration( + hass, bulb_type=FAKE_OLD_FIRMWARE_DIMMABLE_BULB + ) + entity_id = "light.mock_title" + await hass.services.async_call( + LIGHT_DOMAIN, + SERVICE_TURN_ON, + {ATTR_ENTITY_ID: entity_id, ATTR_BRIGHTNESS: 128}, + blocking=True, + ) + pilot: PilotBuilder = bulb.turn_on.mock_calls[0][1][0] + assert pilot.pilot_params == {"dimming": 50, "state": True} + + await async_push_update(hass, bulb, {"mac": FAKE_MAC, **pilot.pilot_params}) + state = hass.states.get(entity_id) + assert state.state == STATE_ON + assert state.attributes[ATTR_BRIGHTNESS] == 128 + + bulb.turn_on.reset_mock() + await hass.services.async_call( + LIGHT_DOMAIN, + SERVICE_TURN_ON, + {ATTR_ENTITY_ID: entity_id, ATTR_BRIGHTNESS: 255}, + blocking=True, + ) + pilot: PilotBuilder = bulb.turn_on.mock_calls[0][1][0] + assert pilot.pilot_params == {"dimming": 100, "state": True}