1515from homeassistant .core import callback
1616from 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
140146 ],
141147}
142148
149+ INDICATE_ACTIVE_LOCAL_DEVICE = [
150+ "boiler_state" ,
151+ "cooling_state" ,
152+ "flame_state" ,
153+ ]
143154
144155async 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
301365class PwPowerSensor (Entity ):
302366 """Power sensor devices."""
0 commit comments