Skip to content

Commit 2b7bf81

Browse files
committed
👕 improve for washer
1 parent 0fd70bc commit 2b7bf81

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

custom_components/xiaomi_miot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def update(self):
712712

713713
@property
714714
def state(self):
715-
return STATE_ON if self._state else STATE_OFF
715+
return STATE_ON if self.is_on else STATE_OFF
716716

717717
@property
718718
def is_on(self):

custom_components/xiaomi_miot/fan.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,13 @@ def oscillate(self, oscillating: bool):
175175

176176
class FanSubEntity(ToggleSubEntity, FanEntity):
177177

178-
def update(self):
179-
super().update()
178+
def turn_on(self, speed=None, **kwargs):
179+
ret = False
180+
if not self.is_on:
181+
ret = self.call_parent('turn_on', **kwargs)
182+
if speed:
183+
ret = self.set_speed(speed)
184+
return ret
180185

181186
@property
182187
def speed(self):
@@ -203,8 +208,39 @@ def __init__(self, parent, miot_property: MiotProperty, option=None):
203208
self._supported_features = SUPPORT_SET_SPEED
204209

205210
@property
206-
def state(self):
207-
return self._parent.state
211+
def icon(self):
212+
if self._miot_property.name in ['mode']:
213+
return 'mdi:menu'
214+
if self._miot_property.name in ['spin_speed']:
215+
return 'mdi:speedometer'
216+
if self._miot_property.name in ['target_temperature']:
217+
return 'mdi:coolant-temperature'
218+
if self._miot_property.name in ['target_water_level']:
219+
return 'mdi:water-plus'
220+
if self._miot_property.name in ['drying_level']:
221+
return 'mdi:tumble-dryer'
222+
return super().icon
223+
224+
@property
225+
def is_on(self):
226+
if not self._parent.is_on:
227+
return False
228+
sta = self._state_attrs.get(self._attr)
229+
if self._miot_property.name in ['spin_speed']:
230+
return sta != self._miot_property.list_search('no spin')
231+
if self._miot_property.name in ['target_temperature']:
232+
return sta != self._miot_property.list_search('cold')
233+
if self._miot_property.name in ['drying_level']:
234+
return sta != self._miot_property.list_search('none')
235+
return True
236+
237+
def turn_on(self, speed=None, **kwargs):
238+
ret = False
239+
if not self._parent.is_on:
240+
ret = self.call_parent('turn_on', **kwargs)
241+
if speed:
242+
ret = self.set_speed(speed)
243+
return ret
208244

209245
@property
210246
def speed(self):

custom_components/xiaomi_miot/switch.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from .core.miot_spec import (
2222
MiotSpec,
2323
MiotService,
24+
MiotProperty,
2425
)
2526
from .fan import MiotWasherSubEntity
2627

@@ -81,6 +82,12 @@ def device_class(self):
8182
return DEVICE_CLASS_OUTLET
8283
return DEVICE_CLASS_SWITCH
8384

85+
@property
86+
def icon(self):
87+
if self._miot_service.name in ['washer']:
88+
return 'mdi:washing-machine'
89+
return super().icon
90+
8491
async def async_update(self):
8592
await super().async_update()
8693
if self._available:
@@ -103,3 +110,41 @@ async def async_update(self):
103110
class SwitchSubEntity(ToggleSubEntity, SwitchEntity):
104111
def update(self):
105112
super().update()
113+
114+
115+
class MiotWasherActionSubEntity(SwitchSubEntity):
116+
def __init__(self, parent, miot_property: MiotProperty, option=None):
117+
super().__init__(parent, miot_property.full_name, option)
118+
self._miot_property = miot_property
119+
self._miot_service = miot_property.service
120+
self._values_on = miot_property.list_search('Busy', 'Delay')
121+
self._values_off = miot_property.list_search('Off', 'Idle', 'Pause', 'Fault')
122+
123+
def update(self):
124+
super().update()
125+
if self._available:
126+
sta = self._state_attrs.get(self._attr)
127+
self._state = sta not in self._values_off
128+
129+
def turn_on(self, **kwargs):
130+
val = self._values_on[0] if self._values_on else None
131+
return self.miot_action('start_wash', val)
132+
133+
def turn_off(self, **kwargs):
134+
val = self._values_off[0] if self._values_off else None
135+
return self.miot_action('pause', val)
136+
137+
def miot_action(self, act, sta=None):
138+
ret = False
139+
act = self._miot_service.get_action(act)
140+
if act:
141+
ret = self.call_parent('miot_action', self._miot_service.iid, act.iid)
142+
if ret and sta is not None:
143+
self.update_attrs({
144+
self._attr: sta,
145+
})
146+
return ret
147+
148+
@property
149+
def icon(self):
150+
return 'mdi:play-box'

0 commit comments

Comments
 (0)