Skip to content

Commit

Permalink
Fix service call for relative only custom range (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
dext0r committed Dec 19, 2023
1 parent a1de042 commit 9cae358
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion custom_components/yandex_smart_home/capability_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ async def set_instance_state(self, context: Context, state: RangeCapabilityInsta

if state.relative:
if self._increase_value_service_config or self._decrease_value_service_config:
if state.value >= 0:
if state.value > 0:
service_config = self._increase_value_service_config
else:
service_config = self._decrease_value_service_config
Expand Down
2 changes: 1 addition & 1 deletion custom_components/yandex_smart_home/capability_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ async def set_instance_state(self, context: Context, state: RangeCapabilityInsta
self._state_features & media_player.MediaPlayerEntityFeature.PREVIOUS_TRACK
and self._state_features & media_player.MediaPlayerEntityFeature.NEXT_TRACK
):
if state.value >= 0:
if state.value > 0:
service = media_player.SERVICE_MEDIA_NEXT_TRACK
else:
service = media_player.SERVICE_MEDIA_PREVIOUS_TRACK
Expand Down
18 changes: 10 additions & 8 deletions tests/test_capability_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,14 +634,15 @@ async def test_capability_custom_range_relative_override_no_state(hass):
assert calls[0].data == {"entity_id": "input_number.test", "value": "value: 10"}

calls = async_mock_service(hass, "test", "decrease_value")
for value in (-3, -50):
for value in (0, -3, -50):
await cap.set_instance_state(
Context(),
RangeCapabilityInstanceActionState(instance=RangeCapabilityInstance.OPEN, value=value, relative=True),
)
assert len(calls) == 2
assert calls[0].data == {"entity_id": "input_number.test", "value": "value: -3"}
assert calls[1].data == {"entity_id": "input_number.test", "value": "value: -50"}
assert len(calls) == 3
assert calls[0].data == {"entity_id": "input_number.test", "value": "value: 0"}
assert calls[1].data == {"entity_id": "input_number.test", "value": "value: -3"}
assert calls[2].data == {"entity_id": "input_number.test", "value": "value: -50"}


async def test_capability_custom_range_only_relative(hass):
Expand Down Expand Up @@ -682,14 +683,15 @@ async def test_capability_custom_range_only_relative(hass):
assert calls[0].data == {"entity_id": "input_number.test", "value": "value: 10"}

calls = async_mock_service(hass, "test", "decrease_value")
for value in (-3, -50):
for value in (0, -3, -50):
await cap.set_instance_state(
Context(),
RangeCapabilityInstanceActionState(instance=RangeCapabilityInstance.OPEN, value=value, relative=True),
)
assert len(calls) == 2
assert calls[0].data == {"entity_id": "input_number.test", "value": "value: -3"}
assert calls[1].data == {"entity_id": "input_number.test", "value": "value: -50"}
assert len(calls) == 3
assert calls[0].data == {"entity_id": "input_number.test", "value": "value: 0"}
assert calls[1].data == {"entity_id": "input_number.test", "value": "value: -3"}
assert calls[2].data == {"entity_id": "input_number.test", "value": "value: -50"}


async def test_capability_custom_range_no_service(hass):
Expand Down

0 comments on commit 9cae358

Please sign in to comment.