diff --git a/homeassistant/components/nice_go/coordinator.py b/homeassistant/components/nice_go/coordinator.py index d6693db2d8a..dd2d7ccb45e 100644 --- a/homeassistant/components/nice_go/coordinator.py +++ b/homeassistant/components/nice_go/coordinator.py @@ -47,7 +47,7 @@ class NiceGODevice: id: str name: str barrier_status: str - light_status: bool + light_status: bool | None fw_version: str connected: bool vacation_mode: bool @@ -113,7 +113,11 @@ class NiceGOUpdateCoordinator(DataUpdateCoordinator[dict[str, NiceGODevice]]): else: barrier_status = BARRIER_STATUS[int(barrier_status_raw[2])].lower() - light_status = barrier_state.reported["lightStatus"].split(",")[0] == "1" + light_status = ( + barrier_state.reported["lightStatus"].split(",")[0] == "1" + if barrier_state.reported.get("lightStatus") + else None + ) fw_version = barrier_state.reported["deviceFwVersion"] if barrier_state.connectionState: connected = barrier_state.connectionState.connected diff --git a/homeassistant/components/nice_go/light.py b/homeassistant/components/nice_go/light.py index 4a08364688e..aa606dbcb8f 100644 --- a/homeassistant/components/nice_go/light.py +++ b/homeassistant/components/nice_go/light.py @@ -1,6 +1,6 @@ """Nice G.O. light.""" -from typing import Any +from typing import TYPE_CHECKING, Any from homeassistant.components.light import ColorMode, LightEntity from homeassistant.core import HomeAssistant @@ -22,6 +22,7 @@ async def async_setup_entry( async_add_entities( NiceGOLightEntity(coordinator, device_id, device_data.name) for device_id, device_data in coordinator.data.items() + if device_data.light_status is not None ) @@ -35,6 +36,8 @@ class NiceGOLightEntity(NiceGOEntity, LightEntity): @property def is_on(self) -> bool: """Return if the light is on or not.""" + if TYPE_CHECKING: + assert self.data.light_status is not None return self.data.light_status async def async_turn_on(self, **kwargs: Any) -> None: diff --git a/tests/components/nice_go/fixtures/get_all_barriers.json b/tests/components/nice_go/fixtures/get_all_barriers.json index adb0fb4bacd..0597f0038dc 100644 --- a/tests/components/nice_go/fixtures/get_all_barriers.json +++ b/tests/components/nice_go/fixtures/get_all_barriers.json @@ -60,5 +60,35 @@ "connected": true, "updatedTimestamp": "123" } + }, + { + "id": "3", + "type": "WallStation", + "controlLevel": "Owner", + "attr": [ + { + "key": "organization", + "value": "test_organization" + } + ], + "state": { + "deviceId": "3", + "desired": { "key": "value" }, + "reported": { + "displayName": "Test Garage 3", + "autoDisabled": false, + "migrationStatus": "DONE", + "deviceId": "3", + "vcnMode": false, + "deviceFwVersion": "1.2.3.4.5.6", + "barrierStatus": "2,100,0,0,-1,0,3,0" + }, + "timestamp": null, + "version": null + }, + "connectionState": { + "connected": true, + "updatedTimestamp": "123" + } } ] diff --git a/tests/components/nice_go/snapshots/test_cover.ambr b/tests/components/nice_go/snapshots/test_cover.ambr index 391d91584bf..fa65b3b9b4c 100644 --- a/tests/components/nice_go/snapshots/test_cover.ambr +++ b/tests/components/nice_go/snapshots/test_cover.ambr @@ -120,11 +120,11 @@ 'original_device_class': , 'original_icon': None, 'original_name': None, - 'platform': 'linear_garage_door', + 'platform': 'nice_go', 'previous_unique_id': None, 'supported_features': , 'translation_key': None, - 'unique_id': 'test3-GDO', + 'unique_id': '3', 'unit_of_measurement': None, }) # --- @@ -140,7 +140,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': 'opening', + 'state': 'closed', }) # --- # name: test_covers[cover.test_garage_4-entry] diff --git a/tests/components/nice_go/snapshots/test_diagnostics.ambr b/tests/components/nice_go/snapshots/test_diagnostics.ambr index 6f9428ed246..380a867ac60 100644 --- a/tests/components/nice_go/snapshots/test_diagnostics.ambr +++ b/tests/components/nice_go/snapshots/test_diagnostics.ambr @@ -20,6 +20,15 @@ 'name': 'Test Garage 2', 'vacation_mode': True, }), + '3': dict({ + 'barrier_status': 'closed', + 'connected': True, + 'fw_version': '1.2.3.4.5.6', + 'id': '3', + 'light_status': None, + 'name': 'Test Garage 3', + 'vacation_mode': False, + }), }), 'entry': dict({ 'data': dict({ diff --git a/tests/components/nice_go/test_light.py b/tests/components/nice_go/test_light.py index e1852581fe6..9c860c0225f 100644 --- a/tests/components/nice_go/test_light.py +++ b/tests/components/nice_go/test_light.py @@ -78,6 +78,7 @@ async def test_update_light_state( assert hass.states.get("light.test_garage_1_light").state == STATE_ON assert hass.states.get("light.test_garage_2_light").state == STATE_OFF + assert hass.states.get("light.test_garage_3_light") is None device_update = load_json_object_fixture("device_state_update.json", DOMAIN) await mock_config_entry.runtime_data.on_data(device_update) @@ -86,3 +87,4 @@ async def test_update_light_state( assert hass.states.get("light.test_garage_1_light").state == STATE_OFF assert hass.states.get("light.test_garage_2_light").state == STATE_ON + assert hass.states.get("light.test_garage_3_light") is None