33import logging
44from typing import Dict
55
6- from homeassistant .const import STATE_OFF , STATE_ON
76from homeassistant .core import callback
87from homeassistant .helpers .entity import Entity
98
10- from .const import DOMAIN , WATER_HEATER_ICON
9+ from homeassistant .components .climate .const import (
10+ CURRENT_HVAC_COOL ,
11+ CURRENT_HVAC_HEAT ,
12+ CURRENT_HVAC_IDLE ,
13+ )
14+
15+ from .const import (
16+ CURRENT_HVAC_DHW ,
17+ DOMAIN ,
18+ FLAME_ICON ,
19+ IDLE_ICON ,
20+ WATER_HEATER_ICON ,
21+ )
1122
1223_LOGGER = logging .getLogger (__name__ )
1324
@@ -22,12 +33,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
2233 for dev_id , device in all_devices .items ():
2334 if device ["class" ] == "heater_central" :
2435 data = api .get_device_data (dev_id )
25- if "domestic_hot_water_state" in data :
26- if data ["domestic_hot_water_state" ] is not None :
27- _LOGGER .debug ("Plugwise water_heater Dev %s" , device ["name" ])
28- water_heater = PwWaterHeater (api , updater , device ["name" ], dev_id )
29- devices .append (water_heater )
30- _LOGGER .info ("Added water_heater.%s" , "{}" .format (device ["name" ]))
36+ if "boiler_temperature" in data :
37+ _LOGGER .debug ("Plugwise water_heater Dev %s" , device ["name" ])
38+ water_heater = PwWaterHeater (api , updater , device ["name" ], dev_id )
39+ devices .append (water_heater )
40+ _LOGGER .info ("Added water_heater.%s" , "{}" .format (device ["name" ]))
3141
3242 async_add_entities (devices , True )
3343
@@ -41,7 +51,11 @@ def __init__(self, api, updater, name, dev_id):
4151 self ._updater = updater
4252 self ._name = name
4353 self ._dev_id = dev_id
44- self ._domestic_hot_water_state = None
54+ self ._boiler_state = False
55+ self ._boiler_temp = None
56+ self ._central_heating_state = False
57+ self ._central_heater_water_pressure = None
58+ self ._domestic_hot_water_state = False
4559 self ._unique_id = f"{ dev_id } -water_heater"
4660
4761 @property
@@ -80,15 +94,32 @@ def device_info(self) -> Dict[str, any]:
8094
8195 @property
8296 def state (self ):
83- """Return the state of the sensor."""
84- if self ._domestic_hot_water_state :
85- return STATE_ON
86- return STATE_OFF
97+ """Return the state of the water_heater."""
98+ if self ._central_heating_state or self ._boiler_state :
99+ return CURRENT_HVAC_HEAT
100+ elif self ._domestic_hot_water_state :
101+ return CURRENT_HVAC_DHW
102+ else :
103+ return CURRENT_HVAC_IDLE
104+
105+ @property
106+ def device_state_attributes (self ):
107+ """Return the optional device state attributes."""
108+ attributes = {}
109+ attributes ["current_operation" ] = self .state
110+ attributes ["current_temperature" ] = self ._boiler_temp
111+ attributes ["water_pressure" ] = self ._central_heater_water_pressure
112+ return attributes
87113
88114 @property
89115 def icon (self ):
90116 """Return the icon to use in the frontend."""
91- return WATER_HEATER_ICON
117+ if self ._central_heating_state or self ._boiler_state :
118+ return FLAME_ICON
119+ elif self ._domestic_hot_water_state :
120+ return WATER_HEATER_ICON
121+ else :
122+ return IDLE_ICON
92123
93124 @property
94125 def should_poll (self ):
@@ -97,13 +128,24 @@ def should_poll(self):
97128
98129 def update (self ):
99130 """Update the entity."""
100-
101- _LOGGER .debug ("Update sensor called" )
131+ _LOGGER .debug ("Update water_heater called" )
102132 data = self ._api .get_device_data (self ._dev_id )
103133
104134 if data is None :
105135 _LOGGER .error ("Received no data for device %s." , self ._name )
106136 else :
137+ if "boiler_temperature" in data :
138+ self ._boiler_temp = data ["boiler_temperature" ]
139+ if "central_heater_water_pressure" in data :
140+ self ._central_heater_water_pressure = data ["central_heater_water_pressure" ]
141+ if "boiler_state" in data :
142+ if data ["boiler_state" ] is not None :
143+ self ._boiler_state = (data ["boiler_state" ] == "on" )
144+ if "central_heating_state" in data :
145+ if data ["central_heating_state" ] is not None :
146+ self ._central_heating_state = (
147+ data ["central_heating_state" ] == "on"
148+ )
107149 if "domestic_hot_water_state" in data :
108150 self ._domestic_hot_water_state = (
109151 data ["domestic_hot_water_state" ] == "on"
0 commit comments