Skip to content

Commit

Permalink
Remove deprecated constants (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
dext0r committed Oct 25, 2024
1 parent fa79308 commit cbf0560
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
7 changes: 6 additions & 1 deletion custom_components/yandex_smart_home/capability_onoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_SUPPORTED_FEATURES,
MAJOR_VERSION,
MINOR_VERSION,
SERVICE_CLOSE_COVER,
SERVICE_LOCK,
SERVICE_OPEN_COVER,
Expand Down Expand Up @@ -230,7 +232,10 @@ async def _set_state(self, data: RequestData, state: dict[str, Any]):
@register_capability
class OnOffCapabilityLock(OnOffCapability):
def get_value(self) -> bool:
return self.state.state == lock.STATE_UNLOCKED
if (MAJOR_VERSION == 2024 and MINOR_VERSION >= 10) or MAJOR_VERSION >= 2025:
return self.state.state == lock.LockState.UNLOCKED
else:
return self.state.state == lock.STATE_UNLOCKED

def supported(self) -> bool:
return self.state.domain == lock.DOMAIN
Expand Down
4 changes: 2 additions & 2 deletions custom_components/yandex_smart_home/capability_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ async def set_state(self, data: RequestData, state: dict[str, Any]):
media_player.SERVICE_PLAY_MEDIA, {
ATTR_ENTITY_ID: self.state.entity_id,
media_player.ATTR_MEDIA_CONTENT_ID: int(value),
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.const.MEDIA_TYPE_CHANNEL
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.MediaType.CHANNEL
},
blocking=False, # some tv's do it too slow
context=data.context
Expand All @@ -566,5 +566,5 @@ async def set_state(self, data: RequestData, state: dict[str, Any]):
def _value(self) -> float | None:
media_content_type = self.state.attributes.get(media_player.ATTR_MEDIA_CONTENT_TYPE)

if media_content_type == media_player.const.MEDIA_TYPE_CHANNEL:
if media_content_type == media_player.MediaType.CHANNEL:
return self._convert_to_float(self.state.attributes.get(media_player.ATTR_MEDIA_CONTENT_ID), strict=False)
15 changes: 13 additions & 2 deletions tests/test_capability_onoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
ATTR_SUPPORTED_FEATURES,
CONF_ENTITY_ID,
CONF_SERVICE,
MAJOR_VERSION,
MINOR_VERSION,
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
STATE_OFF,
Expand Down Expand Up @@ -244,7 +246,11 @@ async def test_capability_onoff_media_player(hass):


async def test_capability_onoff_lock(hass):
state = State('lock.test', lock.STATE_UNLOCKED)
if (MAJOR_VERSION == 2024 and MINOR_VERSION >= 10) or MAJOR_VERSION >= 2025:
state = State('lock.test', lock.LockState.UNLOCKED)
else:
state = State('lock.test', lock.STATE_UNLOCKED)

cap = get_exact_one_capability(hass, BASIC_CONFIG, state, CAPABILITIES_ONOFF, ON_OFF_INSTANCE_ON)

assert cap.retrievable
Expand All @@ -261,7 +267,12 @@ async def test_capability_onoff_lock(hass):
assert len(off_calls) == 1
assert off_calls[0].data == {ATTR_ENTITY_ID: state.entity_id}

for s in [lock.STATE_UNLOCKING, lock.STATE_LOCKING]:
if (MAJOR_VERSION == 2024 and MINOR_VERSION >= 10) or MAJOR_VERSION >= 2025:
states = [lock.LockState.UNLOCKING, lock.LockState.LOCKING]
else:
states = [lock.STATE_UNLOCKING, lock.STATE_LOCKING]

for s in states:
state_other = State('lock.test', s)
cap = get_exact_one_capability(hass, BASIC_CONFIG, state_other, CAPABILITIES_ONOFF, ON_OFF_INSTANCE_ON)

Expand Down
12 changes: 6 additions & 6 deletions tests/test_capability_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ async def test_capability_range_channel_set_random(hass, caplog):
assert calls_set[0].data == {
ATTR_ENTITY_ID: state.entity_id,
media_player.ATTR_MEDIA_CONTENT_ID: 15,
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.const.MEDIA_TYPE_CHANNEL
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.MediaType.CHANNEL
}

with pytest.raises(SmartHomeError) as e:
Expand Down Expand Up @@ -693,7 +693,7 @@ async def test_capability_range_channel_set_random_with_value(hass, caplog):
ATTR_SUPPORTED_FEATURES: media_player.MediaPlayerEntityFeature.PLAY_MEDIA,
ATTR_DEVICE_CLASS: media_player.MediaPlayerDeviceClass.TV,
media_player.ATTR_MEDIA_CONTENT_ID: 15,
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.const.MEDIA_TYPE_CHANNEL
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.MediaType.CHANNEL
})
cap = get_exact_one_capability(hass, BASIC_CONFIG, state, CAPABILITIES_RANGE, RANGE_INSTANCE_CHANNEL)
assert cap.retrievable
Expand All @@ -717,19 +717,19 @@ async def test_capability_range_channel_set_random_with_value(hass, caplog):
assert calls_set[0].data == {
ATTR_ENTITY_ID: state.entity_id,
media_player.ATTR_MEDIA_CONTENT_ID: 20,
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.const.MEDIA_TYPE_CHANNEL
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.MediaType.CHANNEL
}
assert calls_set[1].data == {
ATTR_ENTITY_ID: state.entity_id,
media_player.ATTR_MEDIA_CONTENT_ID: 12,
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.const.MEDIA_TYPE_CHANNEL
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.MediaType.CHANNEL
}


async def test_capability_range_channel_value(hass, caplog):
state = State('media_player.test', STATE_OFF, {
ATTR_SUPPORTED_FEATURES: media_player.MediaPlayerEntityFeature.PLAY_MEDIA,
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.const.MEDIA_TYPE_CHANNEL,
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.MediaType.CHANNEL,
media_player.ATTR_MEDIA_CONTENT_ID: '5'
})
cap = get_exact_one_capability(hass, BASIC_CONFIG, state, CAPABILITIES_RANGE, RANGE_INSTANCE_CHANNEL)
Expand All @@ -745,7 +745,7 @@ async def test_capability_range_channel_value(hass, caplog):

state = State('media_player.test', STATE_OFF, {
ATTR_SUPPORTED_FEATURES: media_player.MediaPlayerEntityFeature.PLAY_MEDIA,
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.const.MEDIA_TYPE_CHANNEL,
media_player.ATTR_MEDIA_CONTENT_TYPE: media_player.MediaType.CHANNEL,
media_player.ATTR_MEDIA_CONTENT_ID: 'foo'
})
cap = get_exact_one_capability(hass, BASIC_CONFIG, state, CAPABILITIES_RANGE, RANGE_INSTANCE_CHANNEL)
Expand Down

0 comments on commit cbf0560

Please sign in to comment.