2016-06-10 06:31:36 +00:00
|
|
|
"""
|
|
|
|
Support for the Netatmo devices (Weather Station and Welcome camera).
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/netatmo/
|
|
|
|
"""
|
|
|
|
import logging
|
2016-10-09 15:45:12 +00:00
|
|
|
from datetime import timedelta
|
2016-06-10 06:31:36 +00:00
|
|
|
from urllib.error import HTTPError
|
2016-09-11 19:27:58 +00:00
|
|
|
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2016-06-10 06:31:36 +00:00
|
|
|
from homeassistant.const import (
|
2016-10-09 15:45:12 +00:00
|
|
|
CONF_API_KEY, CONF_PASSWORD, CONF_USERNAME, CONF_DISCOVERY)
|
2016-09-11 19:27:58 +00:00
|
|
|
from homeassistant.helpers import discovery
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
2016-10-09 15:45:12 +00:00
|
|
|
from homeassistant.util import Throttle
|
2016-06-10 06:31:36 +00:00
|
|
|
|
|
|
|
REQUIREMENTS = [
|
|
|
|
'https://github.com/jabesq/netatmo-api-python/archive/'
|
2016-10-08 18:26:01 +00:00
|
|
|
'v0.6.0.zip#lnetatmo==0.6.0']
|
2016-06-10 06:31:36 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
CONF_SECRET_KEY = 'secret_key'
|
|
|
|
|
2016-09-09 14:53:18 +00:00
|
|
|
DOMAIN = 'netatmo'
|
2016-09-11 19:27:58 +00:00
|
|
|
|
2016-06-10 06:31:36 +00:00
|
|
|
NETATMO_AUTH = None
|
2016-10-09 15:45:12 +00:00
|
|
|
DEFAULT_DISCOVERY = True
|
|
|
|
|
|
|
|
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=10)
|
2016-06-10 06:31:36 +00:00
|
|
|
|
2016-09-11 19:27:58 +00:00
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
|
|
|
DOMAIN: vol.Schema({
|
|
|
|
vol.Required(CONF_API_KEY): cv.string,
|
|
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
|
|
vol.Required(CONF_SECRET_KEY): cv.string,
|
|
|
|
vol.Required(CONF_USERNAME): cv.string,
|
2016-10-09 15:45:12 +00:00
|
|
|
vol.Optional(CONF_DISCOVERY, default=DEFAULT_DISCOVERY): cv.boolean,
|
2016-09-11 19:27:58 +00:00
|
|
|
})
|
|
|
|
}, extra=vol.ALLOW_EXTRA)
|
|
|
|
|
2016-06-10 06:31:36 +00:00
|
|
|
|
|
|
|
def setup(hass, config):
|
2016-10-07 07:00:12 +00:00
|
|
|
"""Set up the Netatmo devices."""
|
2016-06-10 06:31:36 +00:00
|
|
|
import lnetatmo
|
|
|
|
|
|
|
|
global NETATMO_AUTH
|
|
|
|
try:
|
2016-09-11 19:27:58 +00:00
|
|
|
NETATMO_AUTH = lnetatmo.ClientAuth(
|
|
|
|
config[DOMAIN][CONF_API_KEY], config[DOMAIN][CONF_SECRET_KEY],
|
|
|
|
config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD],
|
|
|
|
'read_station read_camera access_camera')
|
2016-06-10 06:31:36 +00:00
|
|
|
except HTTPError:
|
2016-10-07 07:00:12 +00:00
|
|
|
_LOGGER.error("Unable to connect to Netatmo API")
|
2016-06-10 06:31:36 +00:00
|
|
|
return False
|
|
|
|
|
2016-10-09 15:45:12 +00:00
|
|
|
if config[DOMAIN][CONF_DISCOVERY]:
|
|
|
|
for component in 'camera', 'sensor', 'binary_sensor':
|
|
|
|
discovery.load_platform(hass, component, DOMAIN, {}, config)
|
2016-06-10 06:31:36 +00:00
|
|
|
|
|
|
|
return True
|
2016-10-09 15:45:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WelcomeData(object):
|
|
|
|
"""Get the latest data from Netatmo."""
|
|
|
|
|
|
|
|
def __init__(self, auth, home=None):
|
|
|
|
"""Initialize the data object."""
|
|
|
|
self.auth = auth
|
|
|
|
self.welcomedata = None
|
|
|
|
self.camera_names = []
|
|
|
|
self.home = home
|
|
|
|
|
|
|
|
def get_camera_names(self):
|
|
|
|
"""Return all module available on the API as a list."""
|
|
|
|
self.camera_names = []
|
|
|
|
self.update()
|
|
|
|
if not self.home:
|
|
|
|
for home in self.welcomedata.cameras:
|
|
|
|
for camera in self.welcomedata.cameras[home].values():
|
|
|
|
self.camera_names.append(camera['name'])
|
|
|
|
else:
|
|
|
|
for camera in self.welcomedata.cameras[self.home].values():
|
|
|
|
self.camera_names.append(camera['name'])
|
|
|
|
return self.camera_names
|
|
|
|
|
|
|
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
|
|
|
def update(self):
|
|
|
|
"""Call the Netatmo API to update the data."""
|
|
|
|
import lnetatmo
|
|
|
|
self.welcomedata = lnetatmo.WelcomeData(self.auth)
|