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 fb656bf.
  • Loading branch information
dext0r committed Feb 18, 2024
1 parent 5881b7d commit 7882c62
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
51 changes: 24 additions & 27 deletions custom_components/yandex_smart_home/capability_onoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,14 @@ def supported(self) -> bool:
return self.state.domain in (scene.DOMAIN, script.DOMAIN)

async def _set_state(self, data: RequestData, state: dict[str, Any]):
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=data.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=data.context
)


@register_capability
Expand All @@ -199,15 +198,14 @@ def supported(self) -> bool:
return self.state.domain == button.DOMAIN

async def _set_state(self, data: RequestData, state: dict[str, Any]):
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=data.context
)
await self.hass.services.async_call(
self.state.domain,
button.SERVICE_PRESS, {
ATTR_ENTITY_ID: self.state.entity_id
},
blocking=True,
context=data.context
)


@register_capability
Expand All @@ -219,15 +217,14 @@ def supported(self) -> bool:
return self.state.domain == input_button.DOMAIN

async def _set_state(self, data: RequestData, state: dict[str, Any]):
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=data.context
)
await self.hass.services.async_call(
self.state.domain,
input_button.SERVICE_PRESS, {
ATTR_ENTITY_ID: self.state.entity_id
},
blocking=True,
context=data.context
)


@register_capability
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 @@ -112,8 +112,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 7882c62

Please sign in to comment.