From 6b2b4e56ebd048e288ecc2aa010cd47e61338c57 Mon Sep 17 00:00:00 2001 From: Evan Severson <208220+eseverson@users.noreply.github.com> Date: Mon, 19 Oct 2026 15:14:45 -0700 Subject: [PATCH] Add select platform to Alpha Bidet Infrared (#187409) --- .../alpha_bidet_infrared/__init__.py | 2 +- .../alpha_bidet_infrared/icons.json | 8 ++ .../alpha_bidet_infrared/quality_scale.yaml | 4 +- .../components/alpha_bidet_infrared/select.py | 91 ++++++++++++ .../alpha_bidet_infrared/strings.json | 20 +++ .../snapshots/test_select.ambr | 129 ++++++++++++++++++ .../alpha_bidet_infrared/test_select.py | 116 ++++++++++++++++ 7 files changed, 367 insertions(+), 3 deletions(-) create mode 100644 homeassistant/components/alpha_bidet_infrared/select.py create mode 100644 tests/components/alpha_bidet_infrared/snapshots/test_select.ambr create mode 100644 tests/components/alpha_bidet_infrared/test_select.py diff --git a/homeassistant/components/alpha_bidet_infrared/__init__.py b/homeassistant/components/alpha_bidet_infrared/__init__.py index b7fe3bfc199b..51aec7e890a9 100644 --- a/homeassistant/components/alpha_bidet_infrared/__init__.py +++ b/homeassistant/components/alpha_bidet_infrared/__init__.py @@ -4,7 +4,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant -PLATFORMS = [Platform.BUTTON] +PLATFORMS = [Platform.BUTTON, Platform.SELECT] async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: diff --git a/homeassistant/components/alpha_bidet_infrared/icons.json b/homeassistant/components/alpha_bidet_infrared/icons.json index f8c34fb69cef..367cacda0bae 100644 --- a/homeassistant/components/alpha_bidet_infrared/icons.json +++ b/homeassistant/components/alpha_bidet_infrared/icons.json @@ -34,6 +34,14 @@ "water_dry_up": { "default": "mdi:chevron-up" } + }, + "select": { + "seat_temperature": { + "default": "mdi:thermometer" + }, + "water_temperature": { + "default": "mdi:thermometer-water" + } } } } diff --git a/homeassistant/components/alpha_bidet_infrared/quality_scale.yaml b/homeassistant/components/alpha_bidet_infrared/quality_scale.yaml index 7f226c4d6370..7a7170924a1f 100644 --- a/homeassistant/components/alpha_bidet_infrared/quality_scale.yaml +++ b/homeassistant/components/alpha_bidet_infrared/quality_scale.yaml @@ -89,11 +89,11 @@ rules: entity-category: status: exempt comment: | - The buttons are the bidet's primary controls and do not need a category. + The buttons and selects are the bidet's primary controls and do not need a category. entity-device-class: status: exempt comment: | - No button device class fits the bidet's controls. + No button or select device class fits the bidet's controls. entity-disabled-by-default: status: exempt comment: | diff --git a/homeassistant/components/alpha_bidet_infrared/select.py b/homeassistant/components/alpha_bidet_infrared/select.py new file mode 100644 index 000000000000..19b01bb8d8ef --- /dev/null +++ b/homeassistant/components/alpha_bidet_infrared/select.py @@ -0,0 +1,91 @@ +"""Select platform for the Alpha Bidet Infrared integration.""" + +from dataclasses import dataclass +from typing import override + +from infrared_protocols.codes.alpha_bidet.jx2 import AlphaBidetJX2LevelCode + +from homeassistant.components.select import SelectEntity, SelectEntityDescription +from homeassistant.config_entries import ConfigEntry +from homeassistant.const import CONF_MODEL +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback +from homeassistant.helpers.restore_state import RestoreEntity + +from .const import AlphaBidetModel +from .entity import AlphaBidetIrEntity + +PARALLEL_UPDATES = 1 + +# The remote sends the level itself rather than a step, so each option maps to one. +LEVELS: dict[str, int] = {"off": 0, "low": 1, "medium": 2, "high": 3} + + +@dataclass(frozen=True, kw_only=True) +class AlphaBidetIrSelectEntityDescription(SelectEntityDescription): + """Describes an Alpha Bidet IR select entity.""" + + level_code: AlphaBidetJX2LevelCode + + +MODEL_SELECTS: dict[ + AlphaBidetModel, tuple[AlphaBidetIrSelectEntityDescription, ...] +] = { + AlphaBidetModel.JX2: ( + AlphaBidetIrSelectEntityDescription( + key="water_temperature", + translation_key="water_temperature", + options=list(LEVELS), + level_code=AlphaBidetJX2LevelCode.WATER_TEMP, + ), + AlphaBidetIrSelectEntityDescription( + key="seat_temperature", + translation_key="seat_temperature", + options=list(LEVELS), + level_code=AlphaBidetJX2LevelCode.SEAT_TEMP, + ), + ), +} + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddConfigEntryEntitiesCallback, +) -> None: + """Set up Alpha Bidet IR selects from a config entry.""" + async_add_entities( + AlphaBidetIrSelect(entry, description) + for description in MODEL_SELECTS[AlphaBidetModel(entry.data[CONF_MODEL])] + ) + + +class AlphaBidetIrSelect(AlphaBidetIrEntity, SelectEntity, RestoreEntity): + """Alpha Bidet IR select entity for a setting sent as an absolute level.""" + + _attr_assumed_state = True + entity_description: AlphaBidetIrSelectEntityDescription + + def __init__( + self, entry: ConfigEntry, description: AlphaBidetIrSelectEntityDescription + ) -> None: + """Initialize Alpha Bidet IR select.""" + super().__init__(entry, unique_id_suffix=description.key) + self.entity_description = description + + @override + async def async_added_to_hass(self) -> None: + """Restore the assumed level, as infrared cannot read it back from the bidet.""" + await super().async_added_to_hass() + last_state = await self.async_get_last_state() + if last_state is not None and last_state.state in LEVELS: + self._attr_current_option = last_state.state + + @override + async def async_select_option(self, option: str) -> None: + """Send the chosen level.""" + await self._send_command( + self.entity_description.level_code.to_command(LEVELS[option]) + ) + self._attr_current_option = option + self.async_write_ha_state() diff --git a/homeassistant/components/alpha_bidet_infrared/strings.json b/homeassistant/components/alpha_bidet_infrared/strings.json index 19a544e46080..b35e7d670e38 100644 --- a/homeassistant/components/alpha_bidet_infrared/strings.json +++ b/homeassistant/components/alpha_bidet_infrared/strings.json @@ -54,6 +54,26 @@ "water_dry_up": { "name": "Water/dry up" } + }, + "select": { + "seat_temperature": { + "name": "Seat temperature", + "state": { + "high": "[%key:common::state::high%]", + "low": "[%key:common::state::low%]", + "medium": "[%key:common::state::medium%]", + "off": "[%key:common::state::off%]" + } + }, + "water_temperature": { + "name": "Water temperature", + "state": { + "high": "[%key:common::state::high%]", + "low": "[%key:common::state::low%]", + "medium": "[%key:common::state::medium%]", + "off": "[%key:common::state::off%]" + } + } } } } diff --git a/tests/components/alpha_bidet_infrared/snapshots/test_select.ambr b/tests/components/alpha_bidet_infrared/snapshots/test_select.ambr new file mode 100644 index 000000000000..234e1789f961 --- /dev/null +++ b/tests/components/alpha_bidet_infrared/snapshots/test_select.ambr @@ -0,0 +1,129 @@ +# serializer version: 1 +# name: test_entities[select.alpha_bidet_jx2_seat_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : list([ + 'off', + 'low', + 'medium', + 'high', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'select', + 'entity_category': None, + 'entity_id': 'select.alpha_bidet_jx2_seat_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Seat temperature', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Seat temperature', + 'platform': 'alpha_bidet_infrared', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'seat_temperature', + 'unique_id': '01JTEST0000000000000000000_seat_temperature', + 'unit_of_measurement': None, + }) +# --- +# name: test_entities[select.alpha_bidet_jx2_seat_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : True, + : 'Alpha Bidet JX2 Seat temperature', + : list([ + 'off', + 'low', + 'medium', + 'high', + ]), + }), + 'context': , + 'entity_id': 'select.alpha_bidet_jx2_seat_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- +# name: test_entities[select.alpha_bidet_jx2_water_temperature-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : list([ + 'off', + 'low', + 'medium', + 'high', + ]), + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'select', + 'entity_category': None, + 'entity_id': 'select.alpha_bidet_jx2_water_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Water temperature', + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Water temperature', + 'platform': 'alpha_bidet_infrared', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'water_temperature', + 'unique_id': '01JTEST0000000000000000000_water_temperature', + 'unit_of_measurement': None, + }) +# --- +# name: test_entities[select.alpha_bidet_jx2_water_temperature-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : True, + : 'Alpha Bidet JX2 Water temperature', + : list([ + 'off', + 'low', + 'medium', + 'high', + ]), + }), + 'context': , + 'entity_id': 'select.alpha_bidet_jx2_water_temperature', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- diff --git a/tests/components/alpha_bidet_infrared/test_select.py b/tests/components/alpha_bidet_infrared/test_select.py new file mode 100644 index 000000000000..07b5bbae380f --- /dev/null +++ b/tests/components/alpha_bidet_infrared/test_select.py @@ -0,0 +1,116 @@ +"""Tests for the Alpha Bidet Infrared select platform.""" + +from unittest.mock import patch + +from infrared_protocols.codes.alpha_bidet.jx2 import AlphaBidetJX2LevelCode +import pytest +from pytest_homeassistant.common import ( + MockConfigEntry, + mock_restore_cache, + snapshot_platform, +) +from pytest_homeassistant.components.common import ( + assert_availability_follows_source_entity, +) +from pytest_homeassistant.components.infrared.common import MockInfraredEmitterEntity +from syrupy.assertion import SnapshotAssertion + +from homeassistant.components.select import ( + ATTR_OPTION, + DOMAIN as SELECT_DOMAIN, + SERVICE_SELECT_OPTION, +) +from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN, Platform +from homeassistant.core import HomeAssistant, State +from homeassistant.helpers import entity_registry as er + +from .conftest import MOCK_INFRARED_EMITTER_ENTITY_ID + +WATER_TEMPERATURE_ENTITY_ID = "select.alpha_bidet_jx2_water_temperature" +SEAT_TEMPERATURE_ENTITY_ID = "select.alpha_bidet_jx2_seat_temperature" + + +@pytest.fixture +def platforms() -> list[Platform]: + """Return platforms to set up.""" + return [Platform.SELECT] + + +@pytest.mark.usefixtures("init_integration") +async def test_entities( + hass: HomeAssistant, + snapshot: SnapshotAssertion, + entity_registry: er.EntityRegistry, + mock_config_entry: MockConfigEntry, +) -> None: + """Test the select entities are created with the correct attributes.""" + await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) + + +@pytest.mark.parametrize( + ("entity_id", "level_code"), + [ + (WATER_TEMPERATURE_ENTITY_ID, AlphaBidetJX2LevelCode.WATER_TEMP), + (SEAT_TEMPERATURE_ENTITY_ID, AlphaBidetJX2LevelCode.SEAT_TEMP), + ], +) +@pytest.mark.parametrize( + ("option", "level"), [("off", 0), ("low", 1), ("medium", 2), ("high", 3)] +) +@pytest.mark.usefixtures("init_integration") +async def test_select_option_sends_absolute_level( + hass: HomeAssistant, + mock_infrared_emitter_entity: MockInfraredEmitterEntity, + entity_id: str, + level_code: AlphaBidetJX2LevelCode, + option: str, + level: int, +) -> None: + """Test selecting a level sends that level, not a step from the current one.""" + await hass.services.async_call( + SELECT_DOMAIN, + SERVICE_SELECT_OPTION, + {ATTR_ENTITY_ID: entity_id, ATTR_OPTION: option}, + blocking=True, + ) + + assert len(mock_infrared_emitter_entity.send_command_calls) == 1 + timings = mock_infrared_emitter_entity.send_command_calls[0].get_raw_timings() + assert timings == level_code.to_command(level).get_raw_timings() + + state = hass.states.get(entity_id) + assert state is not None + assert state.state == option + + +@pytest.mark.parametrize( + ("restored_state", "expected_state"), + [("medium", "medium"), ("bogus", STATE_UNKNOWN)], +) +async def test_state_restored_on_restart( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, + mock_infrared_emitter_entity: MockInfraredEmitterEntity, + platforms: list[Platform], + restored_state: str, + expected_state: str, +) -> None: + """Test the assumed level is restored after a restart, ignoring unknown ones.""" + mock_restore_cache(hass, [State(WATER_TEMPERATURE_ENTITY_ID, restored_state)]) + mock_config_entry.add_to_hass(hass) + + with patch("homeassistant.components.alpha_bidet_infrared.PLATFORMS", platforms): + await hass.config_entries.async_setup(mock_config_entry.entry_id) + await hass.async_block_till_done() + + state = hass.states.get(WATER_TEMPERATURE_ENTITY_ID) + assert state is not None + assert state.state == expected_state + + +@pytest.mark.usefixtures("init_integration") +async def test_select_availability_follows_ir_entity(hass: HomeAssistant) -> None: + """Test a select becomes unavailable when the IR entity is unavailable.""" + await assert_availability_follows_source_entity( + hass, WATER_TEMPERATURE_ENTITY_ID, [MOCK_INFRARED_EMITTER_ENTITY_ID] + )