mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Fix error if light status is missing in Nice G.O. (#126432)
This commit is contained in:
parent
2a36ec3e21
commit
f9e7721653
@ -47,7 +47,7 @@ class NiceGODevice:
|
|||||||
id: str
|
id: str
|
||||||
name: str
|
name: str
|
||||||
barrier_status: str
|
barrier_status: str
|
||||||
light_status: bool
|
light_status: bool | None
|
||||||
fw_version: str
|
fw_version: str
|
||||||
connected: bool
|
connected: bool
|
||||||
vacation_mode: bool
|
vacation_mode: bool
|
||||||
@ -113,7 +113,11 @@ class NiceGOUpdateCoordinator(DataUpdateCoordinator[dict[str, NiceGODevice]]):
|
|||||||
else:
|
else:
|
||||||
barrier_status = BARRIER_STATUS[int(barrier_status_raw[2])].lower()
|
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"]
|
fw_version = barrier_state.reported["deviceFwVersion"]
|
||||||
if barrier_state.connectionState:
|
if barrier_state.connectionState:
|
||||||
connected = barrier_state.connectionState.connected
|
connected = barrier_state.connectionState.connected
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Nice G.O. light."""
|
"""Nice G.O. light."""
|
||||||
|
|
||||||
from typing import Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from homeassistant.components.light import ColorMode, LightEntity
|
from homeassistant.components.light import ColorMode, LightEntity
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -22,6 +22,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities(
|
async_add_entities(
|
||||||
NiceGOLightEntity(coordinator, device_id, device_data.name)
|
NiceGOLightEntity(coordinator, device_id, device_data.name)
|
||||||
for device_id, device_data in coordinator.data.items()
|
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
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return if the light is on or not."""
|
"""Return if the light is on or not."""
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert self.data.light_status is not None
|
||||||
return self.data.light_status
|
return self.data.light_status
|
||||||
|
|
||||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||||
|
@ -60,5 +60,35 @@
|
|||||||
"connected": true,
|
"connected": true,
|
||||||
"updatedTimestamp": "123"
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -120,11 +120,11 @@
|
|||||||
'original_device_class': <CoverDeviceClass.GARAGE: 'garage'>,
|
'original_device_class': <CoverDeviceClass.GARAGE: 'garage'>,
|
||||||
'original_icon': None,
|
'original_icon': None,
|
||||||
'original_name': None,
|
'original_name': None,
|
||||||
'platform': 'linear_garage_door',
|
'platform': 'nice_go',
|
||||||
'previous_unique_id': None,
|
'previous_unique_id': None,
|
||||||
'supported_features': <CoverEntityFeature: 3>,
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
'translation_key': None,
|
'translation_key': None,
|
||||||
'unique_id': 'test3-GDO',
|
'unique_id': '3',
|
||||||
'unit_of_measurement': None,
|
'unit_of_measurement': None,
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
@ -140,7 +140,7 @@
|
|||||||
'last_changed': <ANY>,
|
'last_changed': <ANY>,
|
||||||
'last_reported': <ANY>,
|
'last_reported': <ANY>,
|
||||||
'last_updated': <ANY>,
|
'last_updated': <ANY>,
|
||||||
'state': 'opening',
|
'state': 'closed',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_covers[cover.test_garage_4-entry]
|
# name: test_covers[cover.test_garage_4-entry]
|
||||||
|
@ -20,6 +20,15 @@
|
|||||||
'name': 'Test Garage 2',
|
'name': 'Test Garage 2',
|
||||||
'vacation_mode': True,
|
'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({
|
'entry': dict({
|
||||||
'data': dict({
|
'data': dict({
|
||||||
|
@ -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_1_light").state == STATE_ON
|
||||||
assert hass.states.get("light.test_garage_2_light").state == STATE_OFF
|
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)
|
device_update = load_json_object_fixture("device_state_update.json", DOMAIN)
|
||||||
await mock_config_entry.runtime_data.on_data(device_update)
|
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_1_light").state == STATE_OFF
|
||||||
assert hass.states.get("light.test_garage_2_light").state == STATE_ON
|
assert hass.states.get("light.test_garage_2_light").state == STATE_ON
|
||||||
|
assert hass.states.get("light.test_garage_3_light") is None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user