Add Netatmo climate battery level (#25143)
* Add battery level sensor * Only update battery level if lower or nonexistent
This commit is contained in:
parent
17013c7c2c
commit
831564784a
1 changed files with 30 additions and 1 deletions
|
@ -16,7 +16,9 @@ from homeassistant.components.climate.const import (
|
|||
DEFAULT_MIN_TEMP
|
||||
)
|
||||
from homeassistant.const import (
|
||||
TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_NAME, PRECISION_HALVES, STATE_OFF)
|
||||
TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_NAME, PRECISION_HALVES, STATE_OFF,
|
||||
ATTR_BATTERY_LEVEL
|
||||
)
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
from .const import DATA_NETATMO_AUTH
|
||||
|
@ -142,6 +144,7 @@ class NetatmoThermostat(ClimateDevice):
|
|||
self._operation_list = [HVAC_MODE_AUTO, HVAC_MODE_HEAT]
|
||||
self._support_flags = SUPPORT_FLAGS
|
||||
self._hvac_mode = None
|
||||
self._battery_level = None
|
||||
self.update_without_throttle = False
|
||||
self._module_type = \
|
||||
self._data.room_status.get(room_id, {}).get('module_type')
|
||||
|
@ -274,6 +277,16 @@ class NetatmoThermostat(ClimateDevice):
|
|||
self.update_without_throttle = True
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the thermostat."""
|
||||
attr = {}
|
||||
|
||||
if self._battery_level is not None:
|
||||
attr[ATTR_BATTERY_LEVEL] = self._battery_level
|
||||
|
||||
return attr
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data from NetAtmo API and updates the states."""
|
||||
try:
|
||||
|
@ -297,6 +310,8 @@ class NetatmoThermostat(ClimateDevice):
|
|||
self._preset = \
|
||||
self._data.room_status[self._room_id]["setpoint_mode"]
|
||||
self._hvac_mode = HVAC_MAP_NETATMO[self._preset]
|
||||
self._battery_level = \
|
||||
self._data.room_status[self._room_id].get('battery_level')
|
||||
except KeyError:
|
||||
_LOGGER.error(
|
||||
"The thermostat in room %s seems to be out of reach.",
|
||||
|
@ -423,6 +438,7 @@ class ThermostatData:
|
|||
roomstatus["module_id"] = None
|
||||
roomstatus["heating_status"] = None
|
||||
roomstatus["heating_power_request"] = None
|
||||
batterylevel = None
|
||||
for module_id in homedata_room["module_ids"]:
|
||||
if (self.homedata.modules[self.home][module_id]["type"]
|
||||
== NA_THERM
|
||||
|
@ -433,6 +449,10 @@ class ThermostatData:
|
|||
rid=roomstatus["module_id"]
|
||||
)
|
||||
roomstatus["heating_status"] = self.boilerstatus
|
||||
batterylevel = (
|
||||
self.homestatus
|
||||
.thermostats[roomstatus["module_id"]]
|
||||
.get("battery_level"))
|
||||
elif roomstatus["module_type"] == NA_VALVE:
|
||||
roomstatus["heating_power_request"] = homestatus_room[
|
||||
"heating_power_request"
|
||||
|
@ -445,6 +465,15 @@ class ThermostatData:
|
|||
self.boilerstatus
|
||||
and roomstatus["heating_status"]
|
||||
)
|
||||
batterylevel = (
|
||||
self.homestatus.valves[roomstatus["module_id"]]
|
||||
.get("battery_level"))
|
||||
|
||||
if batterylevel:
|
||||
if roomstatus.get("battery_level") is None:
|
||||
roomstatus["battery_level"] = batterylevel
|
||||
elif batterylevel < roomstatus["battery_level"]:
|
||||
roomstatus["battery_level"] = batterylevel
|
||||
self.room_status[room] = roomstatus
|
||||
except KeyError as err:
|
||||
_LOGGER.error("Update of room %s failed. Error: %s", room, err)
|
||||
|
|
Loading…
Add table
Reference in a new issue