From 6fd0760f25f83840b7172e52216a5d417efe7701 Mon Sep 17 00:00:00 2001 From: Manu <4445816+tr4nt0r@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:07:14 +0100 Subject: [PATCH] Add USB-PD Mode select entity to IronOS integration (#134901) Add USB-PD Mode select entity --- homeassistant/components/iron_os/icons.json | 3 + homeassistant/components/iron_os/select.py | 12 ++++ homeassistant/components/iron_os/strings.json | 7 +++ .../iron_os/snapshots/test_select.ambr | 55 +++++++++++++++++++ tests/components/iron_os/test_select.py | 6 ++ 5 files changed, 83 insertions(+) diff --git a/homeassistant/components/iron_os/icons.json b/homeassistant/components/iron_os/icons.json index ee8badf3c89..6410c561b9d 100644 --- a/homeassistant/components/iron_os/icons.json +++ b/homeassistant/components/iron_os/icons.json @@ -102,6 +102,9 @@ }, "logo_duration": { "default": "mdi:clock-digital" + }, + "usb_pd_mode": { + "default": "mdi:meter-electric-outline" } }, "sensor": { diff --git a/homeassistant/components/iron_os/select.py b/homeassistant/components/iron_os/select.py index 10d8a6fcef5..cc275e7c63c 100644 --- a/homeassistant/components/iron_os/select.py +++ b/homeassistant/components/iron_os/select.py @@ -19,6 +19,7 @@ from pynecil import ( ScrollSpeed, SettingsDataResponse, TempUnit, + USBPDMode, ) from homeassistant.components.select import SelectEntity, SelectEntityDescription @@ -55,6 +56,7 @@ class PinecilSelect(StrEnum): DESC_SCROLL_SPEED = "desc_scroll_speed" LOCKING_MODE = "locking_mode" LOGO_DURATION = "logo_duration" + USB_PD_MODE = "usb_pd_mode" def enum_to_str(enum: Enum | None) -> str | None: @@ -140,6 +142,16 @@ PINECIL_SELECT_DESCRIPTIONS: tuple[IronOSSelectEntityDescription, ...] = ( entity_category=EntityCategory.CONFIG, entity_registry_enabled_default=False, ), + IronOSSelectEntityDescription( + key=PinecilSelect.USB_PD_MODE, + translation_key=PinecilSelect.USB_PD_MODE, + characteristic=CharSetting.USB_PD_MODE, + value_fn=lambda x: enum_to_str(x.get("usb_pd_mode")), + raw_value_fn=lambda value: USBPDMode[value.upper()], + options=["off", "on"], + entity_category=EntityCategory.CONFIG, + entity_registry_enabled_default=False, + ), ) diff --git a/homeassistant/components/iron_os/strings.json b/homeassistant/components/iron_os/strings.json index 548ba1d8127..60168699427 100644 --- a/homeassistant/components/iron_os/strings.json +++ b/homeassistant/components/iron_os/strings.json @@ -166,6 +166,13 @@ "seconds_5": "5 second", "loop": "Loop" } + }, + "usb_pd_mode": { + "name": "Power Delivery 3.1 EPR", + "state": { + "off": "[%key:common::state::off%]", + "on": "[%key:common::state::on%]" + } } }, "sensor": { diff --git a/tests/components/iron_os/snapshots/test_select.ambr b/tests/components/iron_os/snapshots/test_select.ambr index ce6045c1243..e3989fbf863 100644 --- a/tests/components/iron_os/snapshots/test_select.ambr +++ b/tests/components/iron_os/snapshots/test_select.ambr @@ -237,6 +237,61 @@ 'state': 'right_handed', }) # --- +# name: test_state[select.pinecil_power_delivery_3_1_epr-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'options': list([ + 'off', + 'on', + ]), + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'select', + 'entity_category': , + 'entity_id': 'select.pinecil_power_delivery_3_1_epr', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Power Delivery 3.1 EPR', + 'platform': 'iron_os', + 'previous_unique_id': None, + 'supported_features': 0, + 'translation_key': , + 'unique_id': 'c0:ff:ee:c0:ff:ee_usb_pd_mode', + 'unit_of_measurement': None, + }) +# --- +# name: test_state[select.pinecil_power_delivery_3_1_epr-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Pinecil Power Delivery 3.1 EPR', + 'options': list([ + 'off', + 'on', + ]), + }), + 'context': , + 'entity_id': 'select.pinecil_power_delivery_3_1_epr', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': 'unknown', + }) +# --- # name: test_state[select.pinecil_power_source-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ diff --git a/tests/components/iron_os/test_select.py b/tests/components/iron_os/test_select.py index cfd4d8ecbb1..8cc848dd4cb 100644 --- a/tests/components/iron_os/test_select.py +++ b/tests/components/iron_os/test_select.py @@ -16,6 +16,7 @@ from pynecil import ( ScreenOrientationMode, ScrollSpeed, TempUnit, + USBPDMode, ) import pytest from syrupy.assertion import SnapshotAssertion @@ -105,6 +106,11 @@ async def test_state( "loop", (CharSetting.LOGO_DURATION, LogoDuration.LOOP), ), + ( + "select.pinecil_power_delivery_3_1_epr", + "on", + (CharSetting.USB_PD_MODE, USBPDMode.ON), + ), ], ) @pytest.mark.usefixtures("entity_registry_enabled_by_default", "ble_device")