Skip to content

Commit 4a56315

Browse files
authored
Merge pull request #3812 from bramstroker/feat/vacuum-tapering
Add support for vacuum tapering / trickle at 100%
2 parents d1676d6 + ad1fe93 commit 4a56315

4 files changed

Lines changed: 219 additions & 1 deletion

File tree

custom_components/powercalc/strategy/factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _create_playbook(self, config: ConfigType, power_profile: PowerProfile | Non
149149
playbook_config = self._get_strategy_config(CalculationStrategy.PLAYBOOK, config, power_profile)
150150

151151
directory = None
152-
if power_profile and power_profile.calculation_strategy == CalculationStrategy.PLAYBOOK:
152+
if power_profile:
153153
directory = power_profile.get_model_directory()
154154

155155
return PlaybookStrategy(self._hass, playbook_config, directory)

tests/power_profile/device_types/test_vacuum_robot.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
from datetime import timedelta
2+
13
from homeassistant.components.vacuum import STATE_CLEANING, STATE_DOCKED
24
from homeassistant.const import CONF_ENTITY_ID
35
from homeassistant.core import HomeAssistant
46
from homeassistant.helpers.device_registry import DeviceEntry
7+
from homeassistant.util import dt
58
from pytest_homeassistant_custom_component.common import (
69
RegistryEntryWithDefaults,
10+
async_fire_time_changed,
711
mock_device_registry,
812
mock_registry,
913
)
@@ -88,3 +92,77 @@ async def test_vacuum_robot(
8892
await hass.async_block_till_done()
8993

9094
assert hass.states.get(power_sensor_id).state == "1.50"
95+
96+
97+
async def test_with_tapering_playbook(hass: HomeAssistant) -> None:
98+
vacuum_id = "vacuum.roomba"
99+
battery_id = "sensor.roomba_battery"
100+
101+
mock_registry(
102+
hass,
103+
{
104+
vacuum_id: RegistryEntryWithDefaults(
105+
entity_id=vacuum_id,
106+
unique_id="unique_vacuum_1",
107+
platform="test",
108+
device_id="device_1",
109+
),
110+
battery_id: RegistryEntryWithDefaults(
111+
entity_id=battery_id,
112+
unique_id="unique_battery_1",
113+
platform="test",
114+
device_id="device_1",
115+
device_class="battery",
116+
),
117+
},
118+
)
119+
mock_device_registry(
120+
hass,
121+
{
122+
"device_1": DeviceEntry(
123+
id="device_1",
124+
),
125+
},
126+
)
127+
128+
power_sensor_id = "sensor.roomba_power"
129+
130+
await run_powercalc_setup(
131+
hass,
132+
{
133+
CONF_ENTITY_ID: vacuum_id,
134+
CONF_CUSTOM_MODEL_DIRECTORY: get_test_profile_dir("vacuum_robot_tapering"),
135+
},
136+
)
137+
138+
hass.states.async_set(battery_id, 30)
139+
hass.states.async_set(vacuum_id, STATE_DOCKED)
140+
await hass.async_block_till_done()
141+
142+
assert hass.states.get(power_sensor_id).state == "20.00"
143+
144+
hass.states.async_set(battery_id, 100)
145+
hass.states.async_set(vacuum_id, STATE_DOCKED)
146+
await hass.async_block_till_done()
147+
148+
assert hass.states.get(power_sensor_id).state == "0.00"
149+
150+
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=1))
151+
await hass.async_block_till_done()
152+
153+
assert hass.states.get(power_sensor_id).state == "9.00"
154+
155+
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=3))
156+
await hass.async_block_till_done()
157+
158+
assert hass.states.get(power_sensor_id).state == "5.00"
159+
160+
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=5))
161+
await hass.async_block_till_done()
162+
163+
assert hass.states.get(power_sensor_id).state == "3.00"
164+
165+
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=60))
166+
await hass.async_block_till_done()
167+
168+
assert hass.states.get(power_sensor_id).state == "3.00"
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
{
2+
"calculation_enabled_condition": "{{ is_state('[[entity]]', 'docked') }}",
3+
"calculation_strategy": "composite",
4+
"device_type": "vacuum_robot",
5+
"composite_config": [
6+
{
7+
"condition": {
8+
"condition": "state",
9+
"entity_id": "[[entity_by_device_class:battery]]",
10+
"state": "100"
11+
},
12+
"playbook": {
13+
"autostart": "playbook1",
14+
"playbooks": {
15+
"playbook1": "playbook1.csv"
16+
}
17+
}
18+
},
19+
{
20+
"linear": {
21+
"calibrate": [
22+
"0 -> 20",
23+
"1 -> 20",
24+
"2 -> 20",
25+
"3 -> 20",
26+
"4 -> 20",
27+
"5 -> 20",
28+
"6 -> 20",
29+
"7 -> 20",
30+
"8 -> 20",
31+
"9 -> 20",
32+
"10 -> 20",
33+
"11 -> 20",
34+
"12 -> 20",
35+
"13 -> 20",
36+
"14 -> 20",
37+
"15 -> 20",
38+
"16 -> 20",
39+
"17 -> 20",
40+
"18 -> 20",
41+
"19 -> 20",
42+
"20 -> 20",
43+
"21 -> 20",
44+
"22 -> 20",
45+
"23 -> 20",
46+
"24 -> 20",
47+
"25 -> 20",
48+
"26 -> 20",
49+
"27 -> 20",
50+
"28 -> 20",
51+
"29 -> 20",
52+
"30 -> 20",
53+
"31 -> 20",
54+
"32 -> 20",
55+
"33 -> 20",
56+
"34 -> 20",
57+
"35 -> 20",
58+
"36 -> 20",
59+
"37 -> 20",
60+
"38 -> 20",
61+
"39 -> 20",
62+
"40 -> 20",
63+
"41 -> 20",
64+
"42 -> 20",
65+
"43 -> 20",
66+
"44 -> 20",
67+
"45 -> 20",
68+
"46 -> 20",
69+
"47 -> 20",
70+
"48 -> 20",
71+
"49 -> 20",
72+
"50 -> 20",
73+
"51 -> 20",
74+
"52 -> 20",
75+
"53 -> 20",
76+
"54 -> 20",
77+
"55 -> 20",
78+
"56 -> 20",
79+
"57 -> 20",
80+
"58 -> 20",
81+
"59 -> 20",
82+
"60 -> 20",
83+
"61 -> 20",
84+
"62 -> 20",
85+
"63 -> 20",
86+
"64 -> 20",
87+
"65 -> 20",
88+
"66 -> 20",
89+
"67 -> 20",
90+
"68 -> 20",
91+
"69 -> 20",
92+
"70 -> 20",
93+
"71 -> 20",
94+
"72 -> 20",
95+
"73 -> 20",
96+
"74 -> 20",
97+
"75 -> 20",
98+
"76 -> 20",
99+
"77 -> 20",
100+
"78 -> 20",
101+
"79 -> 20",
102+
"80 -> 15",
103+
"81 -> 15",
104+
"82 -> 15",
105+
"83 -> 15",
106+
"84 -> 15",
107+
"85 -> 15",
108+
"86 -> 15",
109+
"87 -> 15",
110+
"88 -> 15",
111+
"89 -> 15",
112+
"90 -> 15",
113+
"91 -> 15",
114+
"92 -> 15",
115+
"93 -> 15",
116+
"94 -> 15",
117+
"95 -> 15",
118+
"96 -> 15",
119+
"97 -> 15",
120+
"98 -> 15",
121+
"99 -> 8.5",
122+
"100 -> 1.5"
123+
]
124+
}
125+
}
126+
],
127+
"measure_description": "Measured with utils/measure script",
128+
"measure_device": "Shelly Plug S",
129+
"measure_method": "script",
130+
"measure_settings": {
131+
"SAMPLE_COUNT": 1,
132+
"SLEEP_TIME": 0,
133+
"VERSION": "master"
134+
},
135+
"name": "Vacuum test",
136+
"standby_power": 0
137+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
0,9
2+
2,5
3+
4,3

0 commit comments

Comments
 (0)