Add output mode select to Bosch SHC (#187898)

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas
2026-10-26 10:40:22 +01:00
committed by GitHub
co-authored by Claude Sonnet 5.5
parent c91f95ad3e
commit a597c35cc6
4 changed files with 100 additions and 0 deletions
@@ -303,6 +303,29 @@ ACTUATOR_TYPE_DESCRIPTION = SHCSelectEntityDescription[SHCMicromoduleRelay](
)
def _output_mode_select_option(device: SHCMicromoduleRelay, option: str) -> None:
"""Write the relay's output mode."""
device.output_mode = SwitchConfiguration.OutputMode[option.upper()]
OUTPUT_MODE_DESCRIPTION = SHCSelectEntityDescription[SHCMicromoduleRelay](
key="output_mode",
translation_key="output_mode",
entity_category=EntityCategory.CONFIG,
options=[
"attached",
"detached",
"detached_short_press",
"detached_long_press",
"unsupported",
],
current_option_fn=lambda device, options: (
value.name.lower() if (value := device.output_mode) else None
),
select_option_fn=_output_mode_select_option,
)
async def async_setup_entry(
hass: HomeAssistant,
config_entry: BoschConfigEntry,
@@ -486,6 +509,17 @@ async def async_setup_entry(
for relay in session.device_helper.micromodule_relays
if relay.supports_switch_configuration and relay.actuator_type is not None
)
entities.extend(
SHCSelect(
hass=hass,
device=relay,
parent_id=shc_info.unique_id,
entry_id=config_entry.entry_id,
description=OUTPUT_MODE_DESCRIPTION,
)
for relay in session.device_helper.micromodule_relays
if relay.supports_switch_configuration and relay.output_mode is not None
)
async_add_entities(entities)
@@ -131,6 +131,16 @@
"middle": "[%key:common::state::medium%]"
}
},
"output_mode": {
"name": "Output mode",
"state": {
"attached": "Coupled",
"detached": "Disconnected on any key press",
"detached_long_press": "Disconnected on long press",
"detached_short_press": "Disconnected on short press",
"unsupported": "Unsupported"
}
},
"siren_sound_level": {
"name": "Siren volume",
"state": {
+2
View File
@@ -598,6 +598,7 @@ def micromodule_relay_device(
impulse_length_raises_key_error: bool = False,
switch_type: SwitchConfiguration.SwitchType | None = None,
actuator_type: SwitchConfiguration.ActuatorType | None = None,
output_mode: SwitchConfiguration.OutputMode | None = None,
) -> SHCMicromoduleRelay:
"""Build a minimal device double for the micromodule_relays bucket."""
device = create_autospec(SHCMicromoduleRelay, instance=True, spec_set=True)
@@ -617,6 +618,7 @@ def micromodule_relay_device(
device.swap_outputs = swap_outputs
device.switch_type = switch_type
device.actuator_type = actuator_type
device.output_mode = output_mode
if impulse_length_raises_key_error:
type(device).impulse_length = PropertyMock(
side_effect=KeyError("impulseLength")
+54
View File
@@ -790,3 +790,57 @@ async def test_relay_actuator_type_unsupported(
await setup_integration(hass, mock_config_entry)
assert hass.states.get(ACTUATOR_TYPE_ENTITY_ID) is None
OUTPUT_MODE_ENTITY_ID = "select.relay_output_mode"
@pytest.mark.parametrize(
"device_buckets",
[
{
"micromodule_relays": [
micromodule_relay_device(
supports_switch_configuration=True,
output_mode=SwitchConfiguration.OutputMode.ATTACHED,
)
]
}
],
indirect=True,
)
@pytest.mark.usefixtures("mock_session")
async def test_relay_output_mode(
hass: HomeAssistant,
mock_session: MagicMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""The relay output mode is reported and written to the device."""
await setup_integration(hass, mock_config_entry)
device = mock_session.device_helper.micromodule_relays[0]
assert hass.states.get(OUTPUT_MODE_ENTITY_ID).state == "attached"
await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: OUTPUT_MODE_ENTITY_ID, "option": "detached"},
blocking=True,
)
assert device.output_mode == SwitchConfiguration.OutputMode.DETACHED
@pytest.mark.parametrize(
"device_buckets",
[{"micromodule_relays": [micromodule_relay_device()]}],
indirect=True,
)
@pytest.mark.usefixtures("mock_session")
async def test_relay_output_mode_unsupported(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
) -> None:
"""No output mode select is created without switch configuration support."""
await setup_integration(hass, mock_config_entry)
assert hass.states.get(OUTPUT_MODE_ENTITY_ID) is None