Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2270950

Browse files
edenhausCopilot
andauthored
Add Ecovacs custom water amount entity (home-assistant#152782)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f0c0492 commit 2270950

File tree

5 files changed

+243
-8
lines changed

5 files changed

+243
-8
lines changed

‎homeassistant/components/ecovacs/number.py‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
from collections.abc import Callable
66
from dataclasses import dataclass
77

8-
from deebot_client.capabilities import CapabilitySet
8+
from deebot_client.capabilities import CapabilityNumber, CapabilitySet
9+
from deebot_client.device import Device
910
from deebot_client.events import CleanCountEvent, CutDirectionEvent, VolumeEvent
1011
from deebot_client.events.base import Event
12+
from deebot_client.events.water_info import WaterCustomAmountEvent
1113

1214
from homeassistant.components.number import (
1315
NumberEntity,
@@ -75,6 +77,19 @@ class EcovacsNumberEntityDescription[EventT: Event](
7577
native_step=1.0,
7678
mode=NumberMode.BOX,
7779
),
80+
EcovacsNumberEntityDescription[WaterCustomAmountEvent](
81+
capability_fn=lambda caps: (
82+
caps.water.amount
83+
if caps.water and isinstance(caps.water.amount, CapabilityNumber)
84+
else None
85+
),
86+
value_fn=lambda e: e.value,
87+
key="water_amount",
88+
translation_key="water_amount",
89+
entity_category=EntityCategory.CONFIG,
90+
native_step=1.0,
91+
mode=NumberMode.BOX,
92+
),
7893
)
7994

8095

@@ -100,6 +115,18 @@ class EcovacsNumberEntity[EventT: Event](
100115

101116
entity_description: EcovacsNumberEntityDescription
102117

118+
def __init__(
119+
self,
120+
device: Device,
121+
capability: CapabilitySet[EventT, [int]],
122+
entity_description: EcovacsNumberEntityDescription,
123+
) -> None:
124+
"""Initialize entity."""
125+
super().__init__(device, capability, entity_description)
126+
if isinstance(capability, CapabilityNumber):
127+
self._attr_native_min_value = capability.min
128+
self._attr_native_max_value = capability.max
129+
103130
async def async_added_to_hass(self) -> None:
104131
"""Set up the event listeners now that hass is ready."""
105132
await super().async_added_to_hass()

‎homeassistant/components/ecovacs/select.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ class EcovacsSelectEntityDescription[EventT: Event](
3333

3434
ENTITY_DESCRIPTIONS: tuple[EcovacsSelectEntityDescription, ...] = (
3535
EcovacsSelectEntityDescription[WaterAmountEvent](
36-
capability_fn=lambda caps: caps.water.amount
37-
if caps.water and isinstance(caps.water.amount, CapabilitySetTypes)
38-
else None,
36+
capability_fn=lambda caps: (
37+
caps.water.amount
38+
if caps.water and isinstance(caps.water.amount, CapabilitySetTypes)
39+
else None
40+
),
3941
current_option_fn=lambda e: get_name_key(e.value),
4042
options_fn=lambda water: [get_name_key(amount) for amount in water.types],
4143
key="water_amount",

‎homeassistant/components/ecovacs/strings.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
},
103103
"volume": {
104104
"name": "Volume"
105+
},
106+
"water_amount": {
107+
"name": "Water flow level"
105108
}
106109
},
107110
"sensor": {
@@ -176,7 +179,7 @@
176179
},
177180
"select": {
178181
"water_amount": {
179-
"name": "Water flow level",
182+
"name": "[%key:component::ecovacs::entity::number::water_amount::name%]",
180183
"state": {
181184
"high": "[%key:common::state::high%]",
182185
"low": "[%key:common::state::low%]",

‎tests/components/ecovacs/snapshots/test_number.ambr‎

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,177 @@
114114
'state': '3',
115115
})
116116
# ---
117+
# name: test_number_entities[n0vyif][number.x8_pro_omni_clean_count:entity-registry]
118+
EntityRegistryEntrySnapshot({
119+
'aliases': set({
120+
}),
121+
'area_id': None,
122+
'capabilities': dict({
123+
'max': 4,
124+
'min': 1,
125+
'mode': <NumberMode.BOX: 'box'>,
126+
'step': 1.0,
127+
}),
128+
'config_entry_id': <ANY>,
129+
'config_subentry_id': <ANY>,
130+
'device_class': None,
131+
'device_id': <ANY>,
132+
'disabled_by': None,
133+
'domain': 'number',
134+
'entity_category': <EntityCategory.CONFIG: 'config'>,
135+
'entity_id': 'number.x8_pro_omni_clean_count',
136+
'has_entity_name': True,
137+
'hidden_by': None,
138+
'icon': None,
139+
'id': <ANY>,
140+
'labels': set({
141+
}),
142+
'name': None,
143+
'options': dict({
144+
}),
145+
'original_device_class': None,
146+
'original_icon': None,
147+
'original_name': 'Clean count',
148+
'platform': 'ecovacs',
149+
'previous_unique_id': None,
150+
'suggested_object_id': None,
151+
'supported_features': 0,
152+
'translation_key': 'clean_count',
153+
'unique_id': 'E1234567890000000009_clean_count',
154+
'unit_of_measurement': None,
155+
})
156+
# ---
157+
# name: test_number_entities[n0vyif][number.x8_pro_omni_clean_count:state]
158+
StateSnapshot({
159+
'attributes': ReadOnlyDict({
160+
'friendly_name': 'X8 PRO OMNI Clean count',
161+
'max': 4,
162+
'min': 1,
163+
'mode': <NumberMode.BOX: 'box'>,
164+
'step': 1.0,
165+
}),
166+
'context': <ANY>,
167+
'entity_id': 'number.x8_pro_omni_clean_count',
168+
'last_changed': <ANY>,
169+
'last_reported': <ANY>,
170+
'last_updated': <ANY>,
171+
'state': '1',
172+
})
173+
# ---
174+
# name: test_number_entities[n0vyif][number.x8_pro_omni_volume:entity-registry]
175+
EntityRegistryEntrySnapshot({
176+
'aliases': set({
177+
}),
178+
'area_id': None,
179+
'capabilities': dict({
180+
'max': 11,
181+
'min': 0,
182+
'mode': <NumberMode.AUTO: 'auto'>,
183+
'step': 1.0,
184+
}),
185+
'config_entry_id': <ANY>,
186+
'config_subentry_id': <ANY>,
187+
'device_class': None,
188+
'device_id': <ANY>,
189+
'disabled_by': None,
190+
'domain': 'number',
191+
'entity_category': <EntityCategory.CONFIG: 'config'>,
192+
'entity_id': 'number.x8_pro_omni_volume',
193+
'has_entity_name': True,
194+
'hidden_by': None,
195+
'icon': None,
196+
'id': <ANY>,
197+
'labels': set({
198+
}),
199+
'name': None,
200+
'options': dict({
201+
}),
202+
'original_device_class': None,
203+
'original_icon': None,
204+
'original_name': 'Volume',
205+
'platform': 'ecovacs',
206+
'previous_unique_id': None,
207+
'suggested_object_id': None,
208+
'supported_features': 0,
209+
'translation_key': 'volume',
210+
'unique_id': 'E1234567890000000009_volume',
211+
'unit_of_measurement': None,
212+
})
213+
# ---
214+
# name: test_number_entities[n0vyif][number.x8_pro_omni_volume:state]
215+
StateSnapshot({
216+
'attributes': ReadOnlyDict({
217+
'friendly_name': 'X8 PRO OMNI Volume',
218+
'max': 11,
219+
'min': 0,
220+
'mode': <NumberMode.AUTO: 'auto'>,
221+
'step': 1.0,
222+
}),
223+
'context': <ANY>,
224+
'entity_id': 'number.x8_pro_omni_volume',
225+
'last_changed': <ANY>,
226+
'last_reported': <ANY>,
227+
'last_updated': <ANY>,
228+
'state': '5',
229+
})
230+
# ---
231+
# name: test_number_entities[n0vyif][number.x8_pro_omni_water_flow_level:entity-registry]
232+
EntityRegistryEntrySnapshot({
233+
'aliases': set({
234+
}),
235+
'area_id': None,
236+
'capabilities': dict({
237+
'max': 50,
238+
'min': 0,
239+
'mode': <NumberMode.BOX: 'box'>,
240+
'step': 1.0,
241+
}),
242+
'config_entry_id': <ANY>,
243+
'config_subentry_id': <ANY>,
244+
'device_class': None,
245+
'device_id': <ANY>,
246+
'disabled_by': None,
247+
'domain': 'number',
248+
'entity_category': <EntityCategory.CONFIG: 'config'>,
249+
'entity_id': 'number.x8_pro_omni_water_flow_level',
250+
'has_entity_name': True,
251+
'hidden_by': None,
252+
'icon': None,
253+
'id': <ANY>,
254+
'labels': set({
255+
}),
256+
'name': None,
257+
'options': dict({
258+
}),
259+
'original_device_class': None,
260+
'original_icon': None,
261+
'original_name': 'Water flow level',
262+
'platform': 'ecovacs',
263+
'previous_unique_id': None,
264+
'suggested_object_id': None,
265+
'supported_features': 0,
266+
'translation_key': 'water_amount',
267+
'unique_id': 'E1234567890000000009_water_amount',
268+
'unit_of_measurement': None,
269+
})
270+
# ---
271+
# name: test_number_entities[n0vyif][number.x8_pro_omni_water_flow_level:state]
272+
StateSnapshot({
273+
'attributes': ReadOnlyDict({
274+
'friendly_name': 'X8 PRO OMNI Water flow level',
275+
'max': 50,
276+
'min': 0,
277+
'mode': <NumberMode.BOX: 'box'>,
278+
'step': 1.0,
279+
}),
280+
'context': <ANY>,
281+
'entity_id': 'number.x8_pro_omni_water_flow_level',
282+
'last_changed': <ANY>,
283+
'last_reported': <ANY>,
284+
'last_updated': <ANY>,
285+
'state': '14',
286+
})
287+
# ---
117288
# name: test_number_entities[yna5x1][number.ozmo_950_volume:entity-registry]
118289
EntityRegistryEntrySnapshot({
119290
'aliases': set({

‎tests/components/ecovacs/test_number.py‎

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
from dataclasses import dataclass
44

55
from deebot_client.command import Command
6-
from deebot_client.commands.json import SetCutDirection, SetVolume
7-
from deebot_client.events import CutDirectionEvent, Event, VolumeEvent
6+
from deebot_client.commands.json import (
7+
SetCleanCount,
8+
SetCutDirection,
9+
SetVolume,
10+
SetWaterInfo,
11+
)
12+
from deebot_client.events import CleanCountEvent, CutDirectionEvent, Event, VolumeEvent
13+
from deebot_client.events.water_info import WaterCustomAmountEvent
814
import pytest
915
from syrupy.assertion import SnapshotAssertion
1016

@@ -68,8 +74,34 @@ class NumberTestCase:
6874
),
6975
],
7076
),
77+
(
78+
"n0vyif",
79+
[
80+
NumberTestCase(
81+
"number.x8_pro_omni_clean_count",
82+
CleanCountEvent(1),
83+
"1",
84+
4,
85+
SetCleanCount(4),
86+
),
87+
NumberTestCase(
88+
"number.x8_pro_omni_volume",
89+
VolumeEvent(5, 11),
90+
"5",
91+
10,
92+
SetVolume(10),
93+
),
94+
NumberTestCase(
95+
"number.x8_pro_omni_water_flow_level",
96+
WaterCustomAmountEvent(14),
97+
"14",
98+
7,
99+
SetWaterInfo(custom_amount=7),
100+
),
101+
],
102+
),
71103
],
72-
ids=["yna5x1", "5xu9h3"],
104+
ids=["yna5x1", "5xu9h3", "n0vyif"],
73105
)
74106
async def test_number_entities(
75107
hass: HomeAssistant,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /