mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
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:
parent
81d38c3463
commit
8c628071f3
@ -23,9 +23,11 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# These are the available sensors mapped to binary_sensor class
|
||||
SENSOR_TYPES = {
|
||||
"Someone known": "motion",
|
||||
"Someone unknown": "motion",
|
||||
"Motion": "motion",
|
||||
"Someone known": 'occupancy',
|
||||
"Someone unknown": 'motion',
|
||||
"Motion": 'motion',
|
||||
"Tag Vibration": 'vibration',
|
||||
"Tag Open": 'opening',
|
||||
}
|
||||
|
||||
CONF_HOME = 'home'
|
||||
@ -48,6 +50,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
home = config.get(CONF_HOME, None)
|
||||
timeout = config.get(CONF_TIMEOUT, 15)
|
||||
|
||||
module_name = None
|
||||
|
||||
import lnetatmo
|
||||
try:
|
||||
data = WelcomeData(netatmo.NETATMO_AUTH, home)
|
||||
@ -64,23 +68,35 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
camera_name not in config[CONF_CAMERAS]:
|
||||
continue
|
||||
for variable in sensors:
|
||||
add_devices([WelcomeBinarySensor(data, camera_name, home, timeout,
|
||||
variable)])
|
||||
if variable in ('Tag Vibration', 'Tag Open'):
|
||||
continue
|
||||
add_devices([WelcomeBinarySensor(data, camera_name, module_name,
|
||||
home, timeout, variable)])
|
||||
|
||||
for module_name in data.get_module_names(camera_name):
|
||||
for variable in sensors:
|
||||
if variable in ('Tag Vibration', 'Tag Open'):
|
||||
add_devices([WelcomeBinarySensor(data, camera_name,
|
||||
module_name, home,
|
||||
timeout, variable)])
|
||||
|
||||
|
||||
class WelcomeBinarySensor(BinarySensorDevice):
|
||||
"""Represent a single binary sensor in a Netatmo Welcome device."""
|
||||
|
||||
def __init__(self, data, camera_name, home, timeout, sensor):
|
||||
def __init__(self, data, camera_name, module_name, home, timeout, sensor):
|
||||
"""Setup for access to the Netatmo camera events."""
|
||||
self._data = data
|
||||
self._camera_name = camera_name
|
||||
self._module_name = module_name
|
||||
self._home = home
|
||||
self._timeout = timeout
|
||||
if home:
|
||||
self._name = home + ' / ' + camera_name
|
||||
else:
|
||||
self._name = camera_name
|
||||
if module_name:
|
||||
self._name += ' / ' + module_name
|
||||
self._sensor_name = sensor
|
||||
self._name += ' ' + sensor
|
||||
camera_id = data.welcomedata.cameraByName(camera=camera_name,
|
||||
@ -112,7 +128,7 @@ class WelcomeBinarySensor(BinarySensorDevice):
|
||||
def update(self):
|
||||
"""Request an update from the Netatmo API."""
|
||||
self._data.update()
|
||||
self._data.welcomedata.updateEvent(home=self._data.home)
|
||||
self._data.update_event()
|
||||
|
||||
if self._sensor_name == "Someone known":
|
||||
self._state =\
|
||||
@ -129,5 +145,16 @@ class WelcomeBinarySensor(BinarySensorDevice):
|
||||
self._data.welcomedata.motionDetected(self._home,
|
||||
self._camera_name,
|
||||
self._timeout*60)
|
||||
elif self._sensor_name == "Tag Vibration":
|
||||
self._state =\
|
||||
self._data.welcomedata.moduleMotionDetected(self._home,
|
||||
self._module_name,
|
||||
self._camera_name,
|
||||
self._timeout*60)
|
||||
elif self._sensor_name == "Tag Open":
|
||||
self._state =\
|
||||
self._data.welcomedata.moduleOpened(self._home,
|
||||
self._module_name,
|
||||
self._camera_name)
|
||||
else:
|
||||
return None
|
||||
|
@ -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)
|
||||
|
@ -205,7 +205,7 @@ https://github.com/danieljkemp/onkyo-eiscp/archive/python3.zip#onkyo-eiscp==0.9.
|
||||
# https://github.com/deisi/fritzconnection/archive/b5c14515e1c8e2652b06b6316a7f3913df942841.zip#fritzconnection==0.4.6
|
||||
|
||||
# homeassistant.components.netatmo
|
||||
https://github.com/jabesq/netatmo-api-python/archive/v0.7.0.zip#lnetatmo==0.7.0
|
||||
https://github.com/jabesq/netatmo-api-python/archive/v0.8.0.zip#lnetatmo==0.8.0
|
||||
|
||||
# homeassistant.components.neato
|
||||
https://github.com/jabesq/pybotvac/archive/v0.0.1.zip#pybotvac==0.0.1
|
||||
|
Loading…
x
Reference in New Issue
Block a user