Skip to content

Commit

Permalink
Return DEVICE_UNREACHABLE for device without states (close #453)
Browse files Browse the repository at this point in the history
  • Loading branch information
dext0r committed Oct 13, 2023
1 parent 276029d commit d41560a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions custom_components/yandex_smart_home/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ def query(self) -> DeviceState:
if (property_state := p.get_instance_state()) is not None:
properties.append(property_state)

if not capabilities and not properties:
return DeviceState(id=self.id, error_code=ResponseCode.DEVICE_UNREACHABLE)

return DeviceState(id=self.id, capabilities=capabilities, properties=properties)

async def execute(
Expand Down
4 changes: 4 additions & 0 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ async def set_instance_state(self, _: Context, __: ToggleCapabilityInstanceActio
"properties": [{"type": "devices.properties.float", "state": {"instance": "temperature", "value": 5.0}}],
}

state_temp.state = STATE_UNAVAILABLE
with patch.object(Device, "get_capabilities", return_value=[cap_pause]):
assert device.query().as_dict() == {"id": "switch.test", "error_code": "DEVICE_UNREACHABLE"}


async def test_device_execute(hass, caplog):
state = State("switch.test", STATE_ON)
Expand Down

0 comments on commit d41560a

Please sign in to comment.