Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Netatmo climate battery level #25143

Merged
merged 2 commits into from Jul 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 30 additions & 1 deletion homeassistant/components/netatmo/climate.py
Expand Up @@ -16,7 +16,9 @@
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
Expand Down Expand Up @@ -142,6 +144,7 @@ def __init__(self, data, room_id):
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')
Expand Down Expand Up @@ -274,6 +277,16 @@ def set_temperature(self, **kwargs):
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:
Expand All @@ -297,6 +310,8 @@ def update(self):
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.",
Expand Down Expand Up @@ -423,6 +438,7 @@ def update(self):
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
Expand All @@ -433,6 +449,10 @@ def update(self):
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"
Expand All @@ -445,6 +465,15 @@ def update(self):
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
cgtobi marked this conversation as resolved.
Show resolved Hide resolved
self.room_status[room] = roomstatus
except KeyError as err:
_LOGGER.error("Update of room %s failed. Error: %s", room, err)
Expand Down