mirror of
https://github.com/home-assistant/core.git
synced 2026-09-25 17:04:04 -04:00
Remove hour format select from Yoto
https://claude.ai/code/session_015G3sygJ3js3qaMvw7Kn2Jo
This commit is contained in:
@@ -24,7 +24,6 @@ PLATFORMS: list[Platform] = [
|
||||
Platform.BUTTON,
|
||||
Platform.MEDIA_PLAYER,
|
||||
Platform.NUMBER,
|
||||
Platform.SELECT,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
Platform.TIME,
|
||||
|
||||
@@ -31,11 +31,6 @@
|
||||
"default": "mdi:power-sleep"
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"hour_format": {
|
||||
"default": "mdi:clock-digital"
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"card_insertion_state": {
|
||||
"default": "mdi:card-bulleted-outline",
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
"""Select platform for the Yoto integration."""
|
||||
|
||||
from yoto_api import YotoPlayer
|
||||
|
||||
from homeassistant.components.select import SelectEntity
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .coordinator import YotoConfigEntry, YotoDataUpdateCoordinator
|
||||
from .entity import YotoEntity
|
||||
|
||||
PARALLEL_UPDATES = 1
|
||||
|
||||
HOUR_FORMATS = ["12", "24"]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: YotoConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Yoto select platform."""
|
||||
coordinator = entry.runtime_data
|
||||
async_add_entities(
|
||||
YotoHourFormatSelect(coordinator, player)
|
||||
for player in coordinator.client.players.values()
|
||||
)
|
||||
|
||||
|
||||
class YotoHourFormatSelect(YotoEntity, SelectEntity):
|
||||
"""Clock hour format setting of a Yoto player."""
|
||||
|
||||
_attr_translation_key = "hour_format"
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attr_options = HOUR_FORMATS
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: YotoDataUpdateCoordinator,
|
||||
player: YotoPlayer,
|
||||
) -> None:
|
||||
"""Initialize the select."""
|
||||
super().__init__(coordinator, player)
|
||||
self._attr_unique_id = f"{player.id}_hour_format"
|
||||
|
||||
@property
|
||||
def current_option(self) -> str | None:
|
||||
"""Return the configured hour format."""
|
||||
hour_format = self.player.info.config.hour_format
|
||||
if hour_format is None:
|
||||
return None
|
||||
return str(hour_format)
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
"""Update the hour format."""
|
||||
await self._async_set_config(hour_format=int(option))
|
||||
@@ -68,15 +68,6 @@
|
||||
"name": "Auto-shutdown delay"
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"hour_format": {
|
||||
"name": "Hour format",
|
||||
"state": {
|
||||
"12": "12-hour",
|
||||
"24": "24-hour"
|
||||
}
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"card_insertion_state": {
|
||||
"name": "Card slot",
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
# serializer version: 1
|
||||
# name: test_all_entities[select.nursery_yoto_hour_format-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'options': list([
|
||||
'12',
|
||||
'24',
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'select',
|
||||
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||
'entity_id': 'select.nursery_yoto_hour_format',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Hour format',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Hour format',
|
||||
'platform': 'yoto',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'hour_format',
|
||||
'unique_id': 'player-test_hour_format',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[select.nursery_yoto_hour_format-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Nursery Yoto Hour format',
|
||||
'options': list([
|
||||
'12',
|
||||
'24',
|
||||
]),
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'select.nursery_yoto_hour_format',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '12',
|
||||
})
|
||||
# ---
|
||||
@@ -1,86 +0,0 @@
|
||||
"""Tests for the Yoto select platform."""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from yoto_api import YotoError
|
||||
|
||||
from homeassistant.components.select import (
|
||||
ATTR_OPTION,
|
||||
DOMAIN as SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import setup_integration
|
||||
from .conftest import PLAYER_ID
|
||||
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("setup_credentials")
|
||||
|
||||
ENTITY_ID = "select.nursery_yoto_hour_format"
|
||||
|
||||
|
||||
async def _setup(hass: HomeAssistant, mock_config_entry: MockConfigEntry) -> None:
|
||||
"""Set up the integration with only the select platform."""
|
||||
with patch("homeassistant.components.yoto.PLATFORMS", [Platform.SELECT]):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_yoto_client")
|
||||
async def test_all_entities(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Snapshot every Yoto select entity."""
|
||||
await _setup(hass, mock_config_entry)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
||||
|
||||
|
||||
async def test_select_option(
|
||||
hass: HomeAssistant,
|
||||
mock_yoto_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Selecting an hour format writes the player config field."""
|
||||
await _setup(hass, mock_config_entry)
|
||||
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_OPTION: "24"},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
mock_yoto_client.set_player_config.assert_awaited_once_with(
|
||||
PLAYER_ID, hour_format=24
|
||||
)
|
||||
mock_yoto_client.update_player_info.assert_awaited_once_with(PLAYER_ID)
|
||||
|
||||
|
||||
async def test_select_option_failure(
|
||||
hass: HomeAssistant,
|
||||
mock_yoto_client: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""A failed config write raises a Home Assistant error."""
|
||||
await _setup(hass, mock_config_entry)
|
||||
mock_yoto_client.set_player_config.side_effect = YotoError("MQTT timeout")
|
||||
|
||||
with pytest.raises(
|
||||
HomeAssistantError, match="Failed to update Yoto player settings"
|
||||
):
|
||||
await hass.services.async_call(
|
||||
SELECT_DOMAIN,
|
||||
SERVICE_SELECT_OPTION,
|
||||
{ATTR_ENTITY_ID: ENTITY_ID, ATTR_OPTION: "24"},
|
||||
blocking=True,
|
||||
)
|
||||
Reference in New Issue
Block a user