Add support for Netatmo tags (#4761)

* Add support for Netatmo Welcome Tags

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>

* Add size parameter for WelcomeData

* minor fixes

* Add Throttling mechanism for update event

This will prevent to reach the API limit

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>

* Change scan interval for Netatmo Binary sensors

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>

* Minor fixes

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>

* Update netatmo.py
This commit is contained in:
Hugo Dupras 2016-12-06 06:35:33 +01:00 committed by Paulus Schoutsen
parent 81d38c3463
commit 8c628071f3
3 changed files with 56 additions and 11 deletions

View file

@ -18,7 +18,7 @@ from homeassistant.util import Throttle
REQUIREMENTS = [
'https://github.com/jabesq/netatmo-api-python/archive/'
'v0.7.0.zip#lnetatmo==0.7.0']
'v0.8.0.zip#lnetatmo==0.8.0']
_LOGGER = logging.getLogger(__name__)
@ -30,6 +30,7 @@ NETATMO_AUTH = None
DEFAULT_DISCOVERY = True
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=10)
MIN_TIME_BETWEEN_EVENT_UPDATES = timedelta(seconds=10)
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
@ -72,10 +73,11 @@ class WelcomeData(object):
self.auth = auth
self.welcomedata = None
self.camera_names = []
self.module_names = []
self.home = home
def get_camera_names(self):
"""Return all module available on the API as a list."""
"""Return all camera available on the API as a list."""
self.camera_names = []
self.update()
if not self.home:
@ -87,8 +89,24 @@ class WelcomeData(object):
self.camera_names.append(camera['name'])
return self.camera_names
def get_module_names(self, camera_name):
"""Return all module available on the API as a list."""
self.module_names = []
self.update()
cam_id = self.welcomedata.cameraByName(camera=camera_name,
home=self.home)['id']
for module in self.welcomedata.modules.values():
if cam_id == module['cam_id']:
self.module_names.append(module['name'])
return self.module_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)
self.welcomedata = lnetatmo.WelcomeData(self.auth, size=100)
@Throttle(MIN_TIME_BETWEEN_EVENT_UPDATES)
def update_event(self):
"""Call the Netatmo API to update the list of events."""
self.welcomedata.updateEvent(home=self.home)