-
Notifications
You must be signed in to change notification settings - Fork 0
/
waterpurifier.py
195 lines (163 loc) · 5.11 KB
/
waterpurifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import logging
from typing import Any, Dict
from .click_common import command, format_output
from .device import Device
_LOGGER = logging.getLogger(__name__)
class WaterPurifierStatus:
"""Container for status reports from the water purifier."""
def __init__(self, data: Dict[str, Any]) -> None:
self.data = data
@property
def power(self) -> str:
return self.data["power"]
@property
def is_on(self) -> bool:
return self.power == "on"
@property
def mode(self) -> str:
"""Current operation mode."""
return self.data["mode"]
@property
def tds(self) -> str:
return self.data["tds"]
@property
def filter_life_remaining(self) -> int:
"""Time until the filter should be changed."""
return self.data["filter1_life"]
@property
def filter_state(self) -> str:
return self.data["filter1_state"]
@property
def filter2_life_remaining(self) -> int:
"""Time until the filter should be changed."""
return self.data["filter_life"]
@property
def filter2_state(self) -> str:
return self.data["filter_state"]
@property
def life(self) -> str:
return self.data["life"]
@property
def state(self) -> str:
return self.data["state"]
@property
def level(self) -> str:
return self.data["level"]
@property
def volume(self) -> str:
return self.data["volume"]
@property
def filter(self) -> str:
return self.data["filter"]
@property
def usage(self) -> str:
return self.data["usage"]
@property
def temperature(self) -> str:
return self.data["temperature"]
@property
def uv_filter_life_remaining(self) -> int:
"""Time until the filter should be changed."""
return self.data["uv_life"]
@property
def uv_filter_state(self) -> str:
return self.data["uv_state"]
@property
def valve(self) -> str:
return self.data["elecval_state"]
def __repr__(self) -> str:
return (
"<WaterPurifierStatus "
"power=%s, "
"mode=%s, "
"tds=%s, "
"filter_life_remaining=%s, "
"filter_state=%s, "
"filter2_life_remaining=%s, "
"filter2_state=%s, "
"life=%s, "
"state=%s, "
"level=%s, "
"volume=%s, "
"filter=%s, "
"usage=%s, "
"temperature=%s, "
"uv_filter_life_remaining=%s, "
"uv_filter_state=%s, "
"valve=%s>"
% (
self.power,
self.mode,
self.tds,
self.filter_life_remaining,
self.filter_state,
self.filter2_life_remaining,
self.filter2_state,
self.life,
self.state,
self.level,
self.volume,
self.filter,
self.usage,
self.temperature,
self.uv_filter_life_remaining,
self.uv_filter_state,
self.valve,
)
)
class WaterPurifier(Device):
"""Main class representing the waiter purifier."""
@command(
default_output=format_output(
"",
"Power: {result.power}\n"
"Mode: {result.mode}\n"
"TDS: {result.tds}\n"
"Filter life remaining: {result.filter_life_remaining}\n"
"Filter state: {result.filter_state}\n"
"Filter2 life remaining: {result.filter2_life_remaining}\n"
"Filter2 state: {result.filter2_state}\n"
"Life remaining: {result.life_remaining}\n"
"State: {result.state}\n"
"Level: {result.level}\n"
"Volume: {result.volume}\n"
"Filter: {result.filter}\n"
"Usage: {result.usage}\n"
"Temperature: {result.temperature}\n"
"UV filter life remaining: {result.uv_filter_life_remaining}\n"
"UV filter state: {result.uv_filter_state}\n"
"Valve: {result.valve}\n",
)
)
def status(self) -> WaterPurifierStatus:
"""Retrieve properties."""
properties = [
"power",
"mode",
"tds",
"filter1_life",
"filter1_state",
"filter_life",
"filter_state",
"life",
"state",
"level",
"volume",
"filter",
"usage",
"temperature",
"uv_life",
"uv_state",
"elecval_state",
]
_props_per_request = 1
values = self.get_properties(properties, max_properties=_props_per_request)
return WaterPurifierStatus(dict(zip(properties, values)))
@command(default_output=format_output("Powering on"))
def on(self):
"""Power on."""
return self.send("set_power", ["on"])
@command(default_output=format_output("Powering off"))
def off(self):
"""Power off."""
return self.send("set_power", ["off"])