|
3 | 3 | from homeassistant.helpers.device_registry import DeviceInfo |
4 | 4 | from .coordinator import GrowcubeDataCoordinator |
5 | 5 | from homeassistant.components.binary_sensor import BinarySensorEntity, BinarySensorDeviceClass |
6 | | -from .const import DOMAIN |
| 6 | +from .const import DOMAIN, CHANNEL_NAME, CHANNEL_ID |
7 | 7 | import logging |
8 | 8 |
|
9 | 9 | _LOGGER = logging.getLogger(__name__) |
@@ -98,21 +98,15 @@ def update(self) -> None: |
98 | 98 | self._attr_native_value = self._coordinator.data.water_warning |
99 | 99 | self.schedule_update_ha_state() |
100 | 100 |
|
101 | | - #async def async_added_to_hass(self): |
102 | | - # self.async_on_remove(self._coordinator.async_add_listener(self._handle_coordinator_update)) |
103 | | - |
104 | 101 |
|
105 | 102 | class PumpOpenStateSensor(BinarySensorEntity): |
106 | | - _channel_name = ['A', 'B', 'C', 'D'] |
107 | | - _channel_id = ['a', 'b', 'c', 'd'] |
108 | | - |
109 | 103 | def __init__(self, coordinator: GrowcubeDataCoordinator, channel: int) -> None: |
110 | 104 | self._coordinator = coordinator |
111 | 105 | self._coordinator.entities.append(self) |
112 | 106 | self._channel = channel |
113 | | - self._attr_unique_id = f"{coordinator.data.device_id}_pump_" + self._channel_id[channel] + "_open" |
| 107 | + self._attr_unique_id = f"{coordinator.data.device_id}_pump_" + CHANNEL_ID[channel] + "_open" |
114 | 108 | self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" |
115 | | - self._attr_name = f"Pump " + self._channel_name[channel] + " open" |
| 109 | + self._attr_name = f"Pump " + CHANNEL_NAME[channel] + " open" |
116 | 110 | self._attr_device_class = BinarySensorDeviceClass.OPENING |
117 | 111 | self._attr_native_value = coordinator.data.pump_open[self._channel] |
118 | 112 | self._attr_entity_registry_enabled_default = False |
@@ -144,16 +138,13 @@ def update(self) -> None: |
144 | 138 |
|
145 | 139 |
|
146 | 140 | class OutletLockedSensor(BinarySensorEntity): |
147 | | - _channel_name = ['A', 'B', 'C', 'D'] |
148 | | - _channel_id = ['a', 'b', 'c', 'd'] |
149 | | - |
150 | 141 | def __init__(self, coordinator: GrowcubeDataCoordinator, channel: int) -> None: |
151 | 142 | self._coordinator = coordinator |
152 | 143 | self._coordinator.entities.append(self) |
153 | 144 | self._channel = channel |
154 | | - self._attr_unique_id = f"{coordinator.data.device_id}_outlet_" + self._channel_id[channel] + "_locked" |
| 145 | + self._attr_unique_id = f"{coordinator.data.device_id}_outlet_" + CHANNEL_ID[channel] + "_locked" |
155 | 146 | self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" |
156 | | - self._attr_name = f"Outlet " + self._channel_name[channel] + " locked" |
| 147 | + self._attr_name = f"Outlet " + CHANNEL_NAME[channel] + " locked" |
157 | 148 | self._attr_device_class = BinarySensorDeviceClass.PROBLEM |
158 | 149 | self._attr_entity_category = EntityCategory.DIAGNOSTIC |
159 | 150 | self._attr_native_value = coordinator.data.outlet_locked_state[self._channel] |
@@ -185,16 +176,13 @@ def update(self) -> None: |
185 | 176 |
|
186 | 177 |
|
187 | 178 | class OutletBlockedSensor(BinarySensorEntity): |
188 | | - _channel_name = ['A', 'B', 'C', 'D'] |
189 | | - _channel_id = ['a', 'b', 'c', 'd'] |
190 | | - |
191 | 179 | def __init__(self, coordinator: GrowcubeDataCoordinator, channel: int) -> None: |
192 | 180 | self._coordinator = coordinator |
193 | 181 | self._coordinator.entities.append(self) |
194 | 182 | self._channel = channel |
195 | | - self._attr_unique_id = f"{coordinator.data.device_id}_outlet_" + self._channel_id[channel] + "_blocked" |
| 183 | + self._attr_unique_id = f"{coordinator.data.device_id}_outlet_" + self.CHANNEL_ID[channel] + "_blocked" |
196 | 184 | self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" |
197 | | - self._attr_name = f"Outlet " + self._channel_name[channel] + " blocked" |
| 185 | + self._attr_name = f"Outlet " + CHANNEL_NAME[channel] + " blocked" |
198 | 186 | self._attr_device_class = BinarySensorDeviceClass.PROBLEM |
199 | 187 | self._attr_entity_category = EntityCategory.DIAGNOSTIC |
200 | 188 | self._attr_native_value = coordinator.data.outlet_blocked_state[self._channel] |
@@ -226,16 +214,13 @@ def update(self) -> None: |
226 | 214 |
|
227 | 215 |
|
228 | 216 | class SensorFaultSensor(BinarySensorEntity): |
229 | | - _channel_name = ['A', 'B', 'C', 'D'] |
230 | | - _channel_id = ['a', 'b', 'c', 'd'] |
231 | | - |
232 | 217 | def __init__(self, coordinator: GrowcubeDataCoordinator, channel: int) -> None: |
233 | 218 | self._coordinator = coordinator |
234 | 219 | self._coordinator.entities.append(self) |
235 | 220 | self._channel = channel |
236 | | - self._attr_unique_id = f"{coordinator.data.device_id}_sensor_" + self._channel_id[channel] + "_fault" |
| 221 | + self._attr_unique_id = f"{coordinator.data.device_id}_sensor_" + CHANNEL_ID[channel] + "_fault" |
237 | 222 | self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" |
238 | | - self._attr_name = f"Sensor " + self._channel_name[channel] + " fault" |
| 223 | + self._attr_name = f"Sensor " + CHANNEL_NAME[channel] + " fault" |
239 | 224 | self._attr_device_class = BinarySensorDeviceClass.PROBLEM |
240 | 225 | self._attr_entity_category = EntityCategory.DIAGNOSTIC |
241 | 226 | self._attr_native_value = coordinator.data.sensor_abnormal[self._channel] |
@@ -267,16 +252,13 @@ def update(self) -> None: |
267 | 252 |
|
268 | 253 |
|
269 | 254 | class SensorDisconnectedSensor(BinarySensorEntity): |
270 | | - _channel_name = ['A', 'B', 'C', 'D'] |
271 | | - _channel_id = ['a', 'b', 'c', 'd'] |
272 | | - |
273 | 255 | def __init__(self, coordinator: GrowcubeDataCoordinator, channel: int) -> None: |
274 | 256 | self._coordinator = coordinator |
275 | 257 | self._coordinator.entities.append(self) |
276 | 258 | self._channel = channel |
277 | | - self._attr_unique_id = f"{coordinator.data.device_id}_sensor_" + self._channel_id[channel] + "_disconnected" |
| 259 | + self._attr_unique_id = f"{coordinator.data.device_id}_sensor_" + CHANNEL_ID[channel] + "_disconnected" |
278 | 260 | self.entity_id = f"{Platform.SENSOR}.{self._attr_unique_id}" |
279 | | - self._attr_name = f"Sensor " + self._channel_name[channel] + " disconnected" |
| 261 | + self._attr_name = f"Sensor " + CHANNEL_NAME[channel] + " disconnected" |
280 | 262 | self._attr_device_class = BinarySensorDeviceClass.PROBLEM |
281 | 263 | self._attr_entity_category = EntityCategory.DIAGNOSTIC |
282 | 264 | self._attr_native_value = coordinator.data.sensor_disconnected[self._channel] |
|
0 commit comments