Skip to content

Commit 1f4a849

Browse files
authored
Merge pull request #42 from plugwise/replace_water_heater
Replace water_heater by a state-sensor
2 parents 035c754 + 474ca67 commit 1f4a849

File tree

3 files changed

+73
-203
lines changed

3 files changed

+73
-203
lines changed

custom_components/plugwise-beta/__init__.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
_LOGGER = logging.getLogger(__name__)
2121

2222
SENSOR = ["sensor"]
23-
SINGLE = ["binary_sensor", "climate", "sensor", "switch"]
24-
MULTI = ["binary_sensor", "climate", "sensor", "switch", "water_heater"]
23+
CLIMATE = ["binary_sensor", "climate", "sensor", "switch"]
2524

2625

2726
async def async_setup(hass: HomeAssistant, config: dict):
@@ -70,13 +69,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
7069

7170
single_master_thermostat = api.single_master_thermostat()
7271
_LOGGER.debug("Single master thermostat = %s", single_master_thermostat)
73-
if single_master_thermostat is not None:
74-
if single_master_thermostat == True:
75-
PLATFORMS = SINGLE
76-
else:
77-
PLATFORMS = MULTI
78-
else:
72+
if single_master_thermostat is None:
7973
PLATFORMS = SENSOR
74+
else:
75+
PLATFORMS = CLIMATE
8076

8177
for component in PLATFORMS:
8278
hass.async_create_task(

custom_components/plugwise-beta/sensor.py

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
from homeassistant.core import callback
1616
from homeassistant.helpers.entity import Entity
1717

18-
from .const import DEVICE_CLASS_GAS, DOMAIN
18+
from .const import (
19+
DEVICE_CLASS_GAS,
20+
DOMAIN,
21+
COOL_ICON,
22+
FLAME_ICON,
23+
IDLE_ICON,
24+
)
1925

2026
_LOGGER = logging.getLogger(__name__)
2127

@@ -140,6 +146,11 @@
140146
],
141147
}
142148

149+
INDICATE_ACTIVE_LOCAL_DEVICE = [
150+
"boiler_state",
151+
"cooling_state",
152+
"flame_state",
153+
]
143154

144155
async def async_setup_entry(hass, config_entry, async_add_entities):
145156
"""Set up the Smile sensors from a config entry."""
@@ -151,6 +162,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
151162

152163
devices = []
153164
all_devices = api.get_all_devices()
165+
single_thermostat = api.single_master_thermostat()
154166
_LOGGER.debug("Plugwise all devices (not just sensor) %s", all_devices)
155167
for dev_id, device in all_devices.items():
156168
data = api.get_device_data(dev_id)
@@ -189,6 +201,28 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
189201
)
190202
_LOGGER.info("Added sensor.%s", device["name"])
191203

204+
if single_thermostat is not None and not single_thermostat:
205+
idx = 1
206+
for state in INDICATE_ACTIVE_LOCAL_DEVICE:
207+
if state in data:
208+
if idx == 1:
209+
_LOGGER.debug("Plugwise aux sensor Dev %s", device["name"])
210+
devices.append(
211+
PwThermostatSensor(
212+
api,
213+
updater,
214+
device["name"],
215+
dev_id,
216+
"state",
217+
None,
218+
)
219+
)
220+
_LOGGER.info(
221+
"Added sensor.%s_state", "{}".format(device["name"])
222+
)
223+
idx += 1
224+
225+
192226
async_add_entities(devices, True)
193227

194228

@@ -200,14 +234,21 @@ def __init__(self, api, updater, name, dev_id, sensor, sensor_type):
200234
self._api = api
201235
self._updater = updater
202236
self._dev_id = dev_id
203-
self._device = sensor_type[2]
237+
if sensor_type is not None:
238+
self._unit_of_measurement = sensor_type[1]
239+
self._device = sensor_type[2]
240+
self._icon = sensor_type[3]
241+
else:
242+
self._unit_of_measurement = None
243+
self._device = "auxiliary"
204244
self._name = name
205245
self._sensor = sensor
206246
self._sensor_type = sensor_type
207-
self._unit_of_measurement = sensor_type[1]
208-
self._icon = sensor_type[3]
209-
self._class = sensor_type[2]
247+
self._class = self._device
210248
self._state = None
249+
self._boiler_state = False
250+
self._central_heating_state = False
251+
self._cooling_state = False
211252

212253
if self._dev_id == self._api.heater_id:
213254
self._name = f"Auxiliary"
@@ -278,6 +319,12 @@ def unit_of_measurement(self):
278319
@property
279320
def icon(self):
280321
"""Icon for the sensor."""
322+
if self._sensor_type is None:
323+
if self._boiler_state or self._central_heating_state:
324+
return FLAME_ICON
325+
if self._cooling_state:
326+
return COOL_ICON
327+
return IDLE_ICON
281328
return self._icon
282329

283330
def update(self):
@@ -297,6 +344,23 @@ def update(self):
297344
measurement = int(measurement)
298345
self._state = measurement
299346

347+
if "boiler_state" in data:
348+
if data["boiler_state"] is not None:
349+
self._boiler_state = data["boiler_state"]
350+
if "central_heating_state" in data:
351+
if data["central_heating_state"] is not None:
352+
self._central_heating_state = data["central_heating_state"]
353+
if "cooling_state" in data:
354+
if data["cooling_state"] is not None:
355+
self._cooling_state = data["cooling_state"]
356+
if self._sensor == "state":
357+
if self._boiler_state or self._central_heating_state:
358+
self._state = "heating"
359+
elif self._cooling_state:
360+
self._state = "cooling"
361+
else:
362+
self._state = "idle"
363+
300364

301365
class PwPowerSensor(Entity):
302366
"""Power sensor devices."""

custom_components/plugwise-beta/water_heater.py

Lines changed: 0 additions & 190 deletions
This file was deleted.

0 commit comments

Comments
 (0)