Skip to content

Commit bf124da

Browse files
authored
Add SmartThings dustfilter threshold (home-assistant#153909)
1 parent 1682ced commit bf124da

File tree

4 files changed

+177
-3
lines changed

4 files changed

+177
-3
lines changed

homeassistant/components/smartthings/select.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class SmartThingsSelectDescription(SelectEntityDescription):
9898
default_options: list[str] | None = None
9999
extra_components: list[str] | None = None
100100
capability_ignore_list: list[Capability] | None = None
101+
value_is_integer: bool = False
101102

102103

103104
CAPABILITIES_TO_SELECT: dict[Capability | str, SmartThingsSelectDescription] = {
@@ -185,6 +186,15 @@ class SmartThingsSelectDescription(SelectEntityDescription):
185186
options_map=WASHER_WATER_TEMPERATURE_TO_HA,
186187
entity_category=EntityCategory.CONFIG,
187188
),
189+
Capability.SAMSUNG_CE_DUST_FILTER_ALARM: SmartThingsSelectDescription(
190+
key=Capability.SAMSUNG_CE_DUST_FILTER_ALARM,
191+
translation_key="dust_filter_alarm",
192+
options_attribute=Attribute.SUPPORTED_ALARM_THRESHOLDS,
193+
status_attribute=Attribute.ALARM_THRESHOLD,
194+
command=Command.SET_ALARM_THRESHOLD,
195+
entity_category=EntityCategory.CONFIG,
196+
value_is_integer=True,
197+
),
188198
}
189199

190200

@@ -253,6 +263,8 @@ def options(self) -> list[str]:
253263
self.entity_description.options_map.get(option, option)
254264
for option in options
255265
]
266+
if self.entity_description.value_is_integer:
267+
options = [str(option) for option in options]
256268
return options
257269

258270
@property
@@ -263,6 +275,8 @@ def current_option(self) -> str | None:
263275
)
264276
if self.entity_description.options_map:
265277
option = self.entity_description.options_map.get(option)
278+
if self.entity_description.value_is_integer and option is not None:
279+
option = str(option)
266280
return option
267281

268282
async def async_select_option(self, option: str) -> None:
@@ -277,17 +291,20 @@ async def async_select_option(self, option: str) -> None:
277291
raise ServiceValidationError(
278292
"Can only be updated when remote control is enabled"
279293
)
294+
new_option: str | int = option
280295
if self.entity_description.options_map:
281-
option = next(
296+
new_option = next(
282297
(
283298
key
284299
for key, value in self.entity_description.options_map.items()
285300
if value == option
286301
),
287-
option,
302+
new_option,
288303
)
304+
if self.entity_description.value_is_integer:
305+
new_option = int(option)
289306
await self.execute_device_command(
290307
self.entity_description.key,
291308
self.entity_description.command,
292-
option,
309+
new_option,
293310
)

homeassistant/components/smartthings/strings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@
161161
"standard": "Standard"
162162
}
163163
},
164+
"dust_filter_alarm": {
165+
"name": "Dust filter alarm threshold",
166+
"unit_of_measurement": "hours"
167+
},
164168
"flexible_detergent_amount": {
165169
"name": "Flexible compartment dispense amount",
166170
"state": {

tests/components/smartthings/snapshots/test_select.ambr

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,126 @@
11
# serializer version: 1
2+
# name: test_all_entities[da_ac_rac_000003][select.clim_salon_dust_filter_alarm_threshold-entry]
3+
EntityRegistryEntrySnapshot({
4+
'aliases': set({
5+
}),
6+
'area_id': None,
7+
'capabilities': dict({
8+
'options': list([
9+
'180',
10+
'300',
11+
'500',
12+
'700',
13+
]),
14+
}),
15+
'config_entry_id': <ANY>,
16+
'config_subentry_id': <ANY>,
17+
'device_class': None,
18+
'device_id': <ANY>,
19+
'disabled_by': None,
20+
'domain': 'select',
21+
'entity_category': <EntityCategory.CONFIG: 'config'>,
22+
'entity_id': 'select.clim_salon_dust_filter_alarm_threshold',
23+
'has_entity_name': True,
24+
'hidden_by': None,
25+
'icon': None,
26+
'id': <ANY>,
27+
'labels': set({
28+
}),
29+
'name': None,
30+
'options': dict({
31+
}),
32+
'original_device_class': None,
33+
'original_icon': None,
34+
'original_name': 'Dust filter alarm threshold',
35+
'platform': 'smartthings',
36+
'previous_unique_id': None,
37+
'suggested_object_id': None,
38+
'supported_features': 0,
39+
'translation_key': 'dust_filter_alarm',
40+
'unique_id': '1e3f7ca2-e005-e1a4-f6d7-bc231e3f7977_main_samsungce.dustFilterAlarm_alarmThreshold_alarmThreshold',
41+
'unit_of_measurement': None,
42+
})
43+
# ---
44+
# name: test_all_entities[da_ac_rac_000003][select.clim_salon_dust_filter_alarm_threshold-state]
45+
StateSnapshot({
46+
'attributes': ReadOnlyDict({
47+
'friendly_name': 'Clim Salon Dust filter alarm threshold',
48+
'options': list([
49+
'180',
50+
'300',
51+
'500',
52+
'700',
53+
]),
54+
}),
55+
'context': <ANY>,
56+
'entity_id': 'select.clim_salon_dust_filter_alarm_threshold',
57+
'last_changed': <ANY>,
58+
'last_reported': <ANY>,
59+
'last_updated': <ANY>,
60+
'state': '500',
61+
})
62+
# ---
63+
# name: test_all_entities[da_ac_rac_01001][select.aire_dormitorio_principal_dust_filter_alarm_threshold-entry]
64+
EntityRegistryEntrySnapshot({
65+
'aliases': set({
66+
}),
67+
'area_id': None,
68+
'capabilities': dict({
69+
'options': list([
70+
'180',
71+
'300',
72+
'500',
73+
'700',
74+
]),
75+
}),
76+
'config_entry_id': <ANY>,
77+
'config_subentry_id': <ANY>,
78+
'device_class': None,
79+
'device_id': <ANY>,
80+
'disabled_by': None,
81+
'domain': 'select',
82+
'entity_category': <EntityCategory.CONFIG: 'config'>,
83+
'entity_id': 'select.aire_dormitorio_principal_dust_filter_alarm_threshold',
84+
'has_entity_name': True,
85+
'hidden_by': None,
86+
'icon': None,
87+
'id': <ANY>,
88+
'labels': set({
89+
}),
90+
'name': None,
91+
'options': dict({
92+
}),
93+
'original_device_class': None,
94+
'original_icon': None,
95+
'original_name': 'Dust filter alarm threshold',
96+
'platform': 'smartthings',
97+
'previous_unique_id': None,
98+
'suggested_object_id': None,
99+
'supported_features': 0,
100+
'translation_key': 'dust_filter_alarm',
101+
'unique_id': '4ece486b-89db-f06a-d54d-748b676b4d8e_main_samsungce.dustFilterAlarm_alarmThreshold_alarmThreshold',
102+
'unit_of_measurement': None,
103+
})
104+
# ---
105+
# name: test_all_entities[da_ac_rac_01001][select.aire_dormitorio_principal_dust_filter_alarm_threshold-state]
106+
StateSnapshot({
107+
'attributes': ReadOnlyDict({
108+
'friendly_name': 'Aire Dormitorio Principal Dust filter alarm threshold',
109+
'options': list([
110+
'180',
111+
'300',
112+
'500',
113+
'700',
114+
]),
115+
}),
116+
'context': <ANY>,
117+
'entity_id': 'select.aire_dormitorio_principal_dust_filter_alarm_threshold',
118+
'last_changed': <ANY>,
119+
'last_reported': <ANY>,
120+
'last_updated': <ANY>,
121+
'state': '500',
122+
})
123+
# ---
2124
# name: test_all_entities[da_ks_microwave_0101x][select.microwave_lamp-entry]
3125
EntityRegistryEntrySnapshot({
4126
'aliases': set({

tests/components/smartthings/test_select.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,34 @@ async def test_availability_at_start(
189189
"""Test unavailable at boot."""
190190
await setup_integration(hass, mock_config_entry)
191191
assert hass.states.get("select.dryer").state == STATE_UNAVAILABLE
192+
193+
194+
@pytest.mark.parametrize("device_fixture", ["da_ac_rac_000003"])
195+
async def test_select_option_as_integer(
196+
hass: HomeAssistant,
197+
devices: AsyncMock,
198+
mock_config_entry: MockConfigEntry,
199+
) -> None:
200+
"""Test selecting an option represented as an integer."""
201+
await setup_integration(hass, mock_config_entry)
202+
203+
state = hass.states.get("select.clim_salon_dust_filter_alarm_threshold")
204+
assert state.state == "500"
205+
assert all(isinstance(option, str) for option in state.attributes[ATTR_OPTIONS])
206+
207+
await hass.services.async_call(
208+
SELECT_DOMAIN,
209+
SERVICE_SELECT_OPTION,
210+
{
211+
ATTR_ENTITY_ID: "select.clim_salon_dust_filter_alarm_threshold",
212+
ATTR_OPTION: "300",
213+
},
214+
blocking=True,
215+
)
216+
devices.execute_device_command.assert_called_once_with(
217+
"1e3f7ca2-e005-e1a4-f6d7-bc231e3f7977",
218+
Capability.SAMSUNG_CE_DUST_FILTER_ALARM,
219+
Command.SET_ALARM_THRESHOLD,
220+
MAIN,
221+
argument=300,
222+
)

0 commit comments

Comments
 (0)