aboutsummaryrefslogtreecommitdiff
path: root/custom_components/hon/switch.py
diff options
context:
space:
mode:
Diffstat (limited to 'custom_components/hon/switch.py')
-rw-r--r--custom_components/hon/switch.py61
1 files changed, 51 insertions, 10 deletions
diff --git a/custom_components/hon/switch.py b/custom_components/hon/switch.py
index b2dcc0b..08ab8ea 100644
--- a/custom_components/hon/switch.py
+++ b/custom_components/hon/switch.py
@@ -1,5 +1,4 @@
1import logging 1import logging
2
3from dataclasses import dataclass 2from dataclasses import dataclass
4from typing import Any 3from typing import Any
5 4
@@ -90,6 +89,51 @@ SWITCHES: dict[str, tuple[HonSwitchEntityDescription, ...]] = {
90 turn_off_key="resumeProgram", 89 turn_off_key="resumeProgram",
91 ), 90 ),
92 ), 91 ),
92 "DW": (
93 HonSwitchEntityDescription(
94 key="active",
95 name="Dish Washer",
96 icon="mdi:dishwasher",
97 turn_on_key="startProgram",
98 turn_off_key="stopProgram",
99 ),
100 HonSwitchEntityDescription(
101 key="startProgram.extraDry",
102 name="Extra Dry",
103 icon="mdi:hair-dryer",
104 entity_category=EntityCategory.CONFIG,
105 ),
106 HonSwitchEntityDescription(
107 key="startProgram.halfLoad",
108 name="Half Load",
109 icon="mdi:fraction-one-half",
110 entity_category=EntityCategory.CONFIG,
111 ),
112 HonSwitchEntityDescription(
113 key="startProgram.openDoor",
114 name="Open Door",
115 icon="mdi:door-open",
116 entity_category=EntityCategory.CONFIG,
117 ),
118 HonSwitchEntityDescription(
119 key="startProgram.threeInOne",
120 name="Three in One",
121 icon="mdi:numeric-3-box-outline",
122 entity_category=EntityCategory.CONFIG,
123 ),
124 HonSwitchEntityDescription(
125 key="startProgram.ecoExpress",
126 name="Eco Express",
127 icon="mdi:sprout",
128 entity_category=EntityCategory.CONFIG,
129 ),
130 HonSwitchEntityDescription(
131 key="startProgram.addDish",
132 name="Add Dish",
133 icon="mdi:silverware-fork-knife",
134 entity_category=EntityCategory.CONFIG,
135 ),
136 ),
93} 137}
94 138
95 139
@@ -139,13 +183,6 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
139 self.entity_description = description 183 self.entity_description = description
140 self._attr_unique_id = f"{super().unique_id}{description.key}" 184 self._attr_unique_id = f"{super().unique_id}{description.key}"
141 185
142 def available(self) -> bool:
143 if self.entity_category == EntityCategory.CONFIG:
144 return (
145 self._device.settings[self.entity_description.key].typology != "fixed"
146 )
147 return True
148
149 @property 186 @property
150 def is_on(self) -> bool | None: 187 def is_on(self) -> bool | None:
151 """Return True if entity is on.""" 188 """Return True if entity is on."""
@@ -161,7 +198,9 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
161 async def async_turn_on(self, **kwargs: Any) -> None: 198 async def async_turn_on(self, **kwargs: Any) -> None:
162 if self.entity_category == EntityCategory.CONFIG: 199 if self.entity_category == EntityCategory.CONFIG:
163 setting = self._device.settings[self.entity_description.key] 200 setting = self._device.settings[self.entity_description.key]
164 setting.value = setting.max 201 setting.value = (
202 setting.max if isinstance(setting, HonParameterRange) else "1"
203 )
165 self.async_write_ha_state() 204 self.async_write_ha_state()
166 else: 205 else:
167 await self._device.commands[self.entity_description.turn_on_key].send() 206 await self._device.commands[self.entity_description.turn_on_key].send()
@@ -169,7 +208,9 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
169 async def async_turn_off(self, **kwargs: Any) -> None: 208 async def async_turn_off(self, **kwargs: Any) -> None:
170 if self.entity_category == EntityCategory.CONFIG: 209 if self.entity_category == EntityCategory.CONFIG:
171 setting = self._device.settings[self.entity_description.key] 210 setting = self._device.settings[self.entity_description.key]
172 setting.value = setting.min 211 setting.value = (
212 setting.min if isinstance(setting, HonParameterRange) else "0"
213 )
173 self.async_write_ha_state() 214 self.async_write_ha_state()
174 else: 215 else:
175 await self._device.commands[self.entity_description.turn_off_key].send() 216 await self._device.commands[self.entity_description.turn_off_key].send()