Skip to content

Commit

Permalink
Revert "Ignore turn off command for only on capabilities (#507)"
Browse files Browse the repository at this point in the history
This reverts commit 74e1ecf.
  • Loading branch information
dext0r committed Feb 18, 2024
1 parent f7a03ea commit ca72642
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
45 changes: 21 additions & 24 deletions custom_components/yandex_smart_home/capability_onoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,13 @@ def supported(self) -> bool:

async def _set_instance_state(self, context: Context, state: OnOffCapabilityInstanceActionState) -> None:
"""Change the capability state."""
if state.value:
await self._hass.services.async_call(
self.state.domain,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: self.state.entity_id},
blocking=self.state.domain != script.DOMAIN,
context=context,
)
await self._hass.services.async_call(
self.state.domain,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: self.state.entity_id},
blocking=self.state.domain != script.DOMAIN,
context=context,
)


@STATE_CAPABILITIES_REGISTRY.register
Expand All @@ -213,14 +212,13 @@ def supported(self) -> bool:

async def _set_instance_state(self, context: Context, state: OnOffCapabilityInstanceActionState) -> None:
"""Change the capability state."""
if state.value:
await self._hass.services.async_call(
self.state.domain,
button.SERVICE_PRESS,
{ATTR_ENTITY_ID: self.state.entity_id},
blocking=True,
context=context,
)
await self._hass.services.async_call(
self.state.domain,
button.SERVICE_PRESS,
{ATTR_ENTITY_ID: self.state.entity_id},
blocking=True,
context=context,
)


@STATE_CAPABILITIES_REGISTRY.register
Expand All @@ -234,14 +232,13 @@ def supported(self) -> bool:

async def _set_instance_state(self, context: Context, state: OnOffCapabilityInstanceActionState) -> None:
"""Change the capability state."""
if state.value:
await self._hass.services.async_call(
self.state.domain,
input_button.SERVICE_PRESS,
{ATTR_ENTITY_ID: self.state.entity_id},
blocking=True,
context=context,
)
await self._hass.services.async_call(
self.state.domain,
input_button.SERVICE_PRESS,
{ATTR_ENTITY_ID: self.state.entity_id},
blocking=True,
context=context,
)


@STATE_CAPABILITIES_REGISTRY.register
Expand Down
3 changes: 2 additions & 1 deletion tests/test_capability_onoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ async def test_capability_onoff_only_on(hass, domain, initial_state, service):
if domain == script.DOMAIN:
await hass.async_block_till_done()

assert len(on_calls) == 1
assert len(on_calls) == 2
assert on_calls[0].data == {ATTR_ENTITY_ID: f"{domain}.test"}
assert on_calls[1].data == {ATTR_ENTITY_ID: f"{domain}.test"}


async def test_capability_onoff_cover(hass):
Expand Down

0 comments on commit ca72642

Please sign in to comment.