Skip to content

Commit

Permalink
Add USB-PD Mode select entity to IronOS integration (home-assistant#1…
Browse files Browse the repository at this point in the history
…34901)

Add USB-PD Mode select entity
  • Loading branch information
tr4nt0r authored Jan 10, 2025
1 parent 59d6110 commit 6fd0760
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
3 changes: 3 additions & 0 deletions homeassistant/components/iron_os/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
},
"logo_duration": {
"default": "mdi:clock-digital"
},
"usb_pd_mode": {
"default": "mdi:meter-electric-outline"
}
},
"sensor": {
Expand Down
12 changes: 12 additions & 0 deletions homeassistant/components/iron_os/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ScrollSpeed,
SettingsDataResponse,
TempUnit,
USBPDMode,
)

from homeassistant.components.select import SelectEntity, SelectEntityDescription
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -140,6 +142,16 @@ def enum_to_str(enum: Enum | None) -> str | None:
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,
),
)


Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/iron_os/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
55 changes: 55 additions & 0 deletions tests/components/iron_os/snapshots/test_select.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'select',
'entity_category': <EntityCategory.CONFIG: 'config'>,
'entity_id': 'select.pinecil_power_delivery_3_1_epr',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'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': <PinecilSelect.USB_PD_MODE: 'usb_pd_mode'>,
'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': <ANY>,
'entity_id': 'select.pinecil_power_delivery_3_1_epr',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# ---
# name: test_state[select.pinecil_power_source-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
Expand Down
6 changes: 6 additions & 0 deletions tests/components/iron_os/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ScreenOrientationMode,
ScrollSpeed,
TempUnit,
USBPDMode,
)
import pytest
from syrupy.assertion import SnapshotAssertion
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 6fd0760

Please sign in to comment.