mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Netatmo, handle missing thermostat devices (#21651)
This commit is contained in:
parent
955b71c44b
commit
7a7080055e
@ -1,18 +1,18 @@
|
|||||||
"""Support for Netatmo Smart thermostats."""
|
"""Support for Netatmo Smart thermostats."""
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
import homeassistant.helpers.config_validation as cv
|
||||||
STATE_OFF, TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_NAME)
|
|
||||||
from homeassistant.components.climate import ClimateDevice, PLATFORM_SCHEMA
|
from homeassistant.components.climate import ClimateDevice, PLATFORM_SCHEMA
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
STATE_HEAT, SUPPORT_ON_OFF, SUPPORT_TARGET_TEMPERATURE,
|
STATE_HEAT, SUPPORT_ON_OFF, SUPPORT_TARGET_TEMPERATURE,
|
||||||
SUPPORT_OPERATION_MODE, SUPPORT_AWAY_MODE, STATE_MANUAL, STATE_AUTO,
|
SUPPORT_OPERATION_MODE, SUPPORT_AWAY_MODE, STATE_MANUAL, STATE_AUTO,
|
||||||
STATE_ECO, STATE_COOL)
|
STATE_ECO, STATE_COOL)
|
||||||
|
from homeassistant.const import (
|
||||||
|
STATE_OFF, TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_NAME)
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
|
|
||||||
|
|
||||||
DEPENDENCIES = ['netatmo']
|
DEPENDENCIES = ['netatmo']
|
||||||
|
|
||||||
@ -86,13 +86,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
else:
|
else:
|
||||||
homes = home_data.get_home_names()
|
homes = home_data.get_home_names()
|
||||||
|
|
||||||
|
devices = []
|
||||||
for home in homes:
|
for home in homes:
|
||||||
_LOGGER.debug("Setting up %s ...", home)
|
_LOGGER.debug("Setting up %s ...", home)
|
||||||
try:
|
try:
|
||||||
room_data = ThermostatData(netatmo.NETATMO_AUTH, home)
|
room_data = ThermostatData(netatmo.NETATMO_AUTH, home)
|
||||||
except pyatmo.NoDevice:
|
except pyatmo.NoDevice:
|
||||||
continue
|
continue
|
||||||
devices = []
|
|
||||||
for room_id in room_data.get_room_ids():
|
for room_id in room_data.get_room_ids():
|
||||||
room_name = room_data.homedata.rooms[home][room_id]['name']
|
room_name = room_data.homedata.rooms[home][room_id]['name']
|
||||||
_LOGGER.debug("Setting up %s (%s) ...", room_name, room_id)
|
_LOGGER.debug("Setting up %s (%s) ...", room_name, room_id)
|
||||||
@ -102,7 +102,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
_LOGGER.debug("Adding devices for room %s (%s) ...",
|
_LOGGER.debug("Adding devices for room %s (%s) ...",
|
||||||
room_name, room_id)
|
room_name, room_id)
|
||||||
devices.append(NetatmoThermostat(room_data, room_id))
|
devices.append(NetatmoThermostat(room_data, room_id))
|
||||||
add_entities(devices, True)
|
add_entities(devices, True)
|
||||||
|
|
||||||
|
|
||||||
class NetatmoThermostat(ClimateDevice):
|
class NetatmoThermostat(ClimateDevice):
|
||||||
@ -142,7 +142,7 @@ class NetatmoThermostat(ClimateDevice):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the thermostat."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -299,6 +299,8 @@ class HomeData:
|
|||||||
def get_home_names(self):
|
def get_home_names(self):
|
||||||
"""Get all the home names returned by NetAtmo API."""
|
"""Get all the home names returned by NetAtmo API."""
|
||||||
self.setup()
|
self.setup()
|
||||||
|
if self.homedata is None:
|
||||||
|
return []
|
||||||
for home in self.homedata.homes:
|
for home in self.homedata.homes:
|
||||||
if 'therm_schedules' in self.homedata.homes[home] and 'modules' \
|
if 'therm_schedules' in self.homedata.homes[home] and 'modules' \
|
||||||
in self.homedata.homes[home]:
|
in self.homedata.homes[home]:
|
||||||
@ -312,9 +314,9 @@ class HomeData:
|
|||||||
self.homedata = pyatmo.HomeData(self.auth)
|
self.homedata = pyatmo.HomeData(self.auth)
|
||||||
self.home_id = self.homedata.gethomeId(self.home)
|
self.home_id = self.homedata.gethomeId(self.home)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
_LOGGER.error("Error when getting homedata.")
|
_LOGGER.error("Error when getting home data.")
|
||||||
except pyatmo.NoDevice:
|
except pyatmo.NoDevice:
|
||||||
_LOGGER.error("Error when getting homestatus response.")
|
_LOGGER.debug("No thermostat devices available.")
|
||||||
|
|
||||||
|
|
||||||
class ThermostatData:
|
class ThermostatData:
|
||||||
@ -337,11 +339,11 @@ class ThermostatData:
|
|||||||
|
|
||||||
def get_room_ids(self):
|
def get_room_ids(self):
|
||||||
"""Return all module available on the API as a list."""
|
"""Return all module available on the API as a list."""
|
||||||
if self.setup():
|
if not self.setup():
|
||||||
for key in self.homestatus.rooms:
|
return []
|
||||||
self.room_ids.append(key)
|
for key in self.homestatus.rooms:
|
||||||
return self.room_ids
|
self.room_ids.append(key)
|
||||||
return []
|
return self.room_ids
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
"""Retrieve HomeData and HomeStatus by NetAtmo API."""
|
"""Retrieve HomeData and HomeStatus by NetAtmo API."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user