mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Hotfix for netatmo cameras (#5644)
* Fix for missing netatmo tags in 0.37 Also fix issue with SSL certificate for vpn_url Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com> * Netatmo welcome: vpn_url can be empty Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com> * add config floag to disable SSL verification for vpn_url Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com> * Import CONF_VERIFY_SSL from const
This commit is contained in:
parent
a72d32b9af
commit
676519d0cb
@ -26,8 +26,6 @@ WELCOME_SENSOR_TYPES = {
|
|||||||
"Someone known": "motion",
|
"Someone known": "motion",
|
||||||
"Someone unknown": "motion",
|
"Someone unknown": "motion",
|
||||||
"Motion": "motion",
|
"Motion": "motion",
|
||||||
"Tag Vibration": 'vibration',
|
|
||||||
"Tag Open": 'opening'
|
|
||||||
}
|
}
|
||||||
PRESENCE_SENSOR_TYPES = {
|
PRESENCE_SENSOR_TYPES = {
|
||||||
"Outdoor motion": "motion",
|
"Outdoor motion": "motion",
|
||||||
@ -35,11 +33,16 @@ PRESENCE_SENSOR_TYPES = {
|
|||||||
"Outdoor animal": "motion",
|
"Outdoor animal": "motion",
|
||||||
"Outdoor vehicle": "motion"
|
"Outdoor vehicle": "motion"
|
||||||
}
|
}
|
||||||
|
TAG_SENSOR_TYPES = {
|
||||||
|
"Tag Vibration": 'vibration',
|
||||||
|
"Tag Open": 'opening'
|
||||||
|
}
|
||||||
|
|
||||||
CONF_HOME = 'home'
|
CONF_HOME = 'home'
|
||||||
CONF_CAMERAS = 'cameras'
|
CONF_CAMERAS = 'cameras'
|
||||||
CONF_WELCOME_SENSORS = 'welcome_sensors'
|
CONF_WELCOME_SENSORS = 'welcome_sensors'
|
||||||
CONF_PRESENCE_SENSORS = 'presence_sensors'
|
CONF_PRESENCE_SENSORS = 'presence_sensors'
|
||||||
|
CONF_TAG_SENSORS = 'tag_sensors'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Optional(CONF_HOME): cv.string,
|
vol.Optional(CONF_HOME): cv.string,
|
||||||
@ -78,6 +81,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
CONF_WELCOME_SENSORS, WELCOME_SENSOR_TYPES)
|
CONF_WELCOME_SENSORS, WELCOME_SENSOR_TYPES)
|
||||||
presence_sensors = config.get(
|
presence_sensors = config.get(
|
||||||
CONF_PRESENCE_SENSORS, PRESENCE_SENSOR_TYPES)
|
CONF_PRESENCE_SENSORS, PRESENCE_SENSOR_TYPES)
|
||||||
|
tag_sensors = config.get(CONF_TAG_SENSORS, TAG_SENSOR_TYPES)
|
||||||
|
|
||||||
for camera_name in data.get_camera_names():
|
for camera_name in data.get_camera_names():
|
||||||
camera_type = data.get_camera_type(camera=camera_name, home=home)
|
camera_type = data.get_camera_type(camera=camera_name, home=home)
|
||||||
@ -103,13 +107,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
variable)])
|
variable)])
|
||||||
|
|
||||||
for module_name in data.get_module_names(camera_name):
|
for module_name in data.get_module_names(camera_name):
|
||||||
for variable in welcome_sensors:
|
for variable in tag_sensors:
|
||||||
if variable in ('Tag Vibration', 'Tag Open'):
|
camera_type = None
|
||||||
add_devices([NetatmoBinarySensor(data, camera_name,
|
add_devices([NetatmoBinarySensor(data, camera_name,
|
||||||
module_name, home,
|
module_name, home,
|
||||||
timeout, offset,
|
timeout, offset,
|
||||||
camera_type,
|
camera_type,
|
||||||
variable)])
|
variable)])
|
||||||
|
|
||||||
|
|
||||||
class NetatmoBinarySensor(BinarySensorDevice):
|
class NetatmoBinarySensor(BinarySensorDevice):
|
||||||
@ -157,7 +161,7 @@ class NetatmoBinarySensor(BinarySensorDevice):
|
|||||||
elif self._cameratype == "NOC":
|
elif self._cameratype == "NOC":
|
||||||
return PRESENCE_SENSOR_TYPES.get(self._sensor_name)
|
return PRESENCE_SENSOR_TYPES.get(self._sensor_name)
|
||||||
else:
|
else:
|
||||||
return None
|
return TAG_SENSOR_TYPES.get(self._sensor_name)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
@ -184,8 +188,6 @@ class NetatmoBinarySensor(BinarySensorDevice):
|
|||||||
self._data.camera_data.motionDetected(self._home,
|
self._data.camera_data.motionDetected(self._home,
|
||||||
self._camera_name,
|
self._camera_name,
|
||||||
self._timeout*60)
|
self._timeout*60)
|
||||||
else:
|
|
||||||
return None
|
|
||||||
elif self._cameratype == "NOC":
|
elif self._cameratype == "NOC":
|
||||||
if self._sensor_name == "Outdoor motion":
|
if self._sensor_name == "Outdoor motion":
|
||||||
self._state =\
|
self._state =\
|
||||||
@ -206,9 +208,7 @@ class NetatmoBinarySensor(BinarySensorDevice):
|
|||||||
self._data.camera_data.carDetected(self._home,
|
self._data.camera_data.carDetected(self._home,
|
||||||
self._camera_name,
|
self._camera_name,
|
||||||
self._offset)
|
self._offset)
|
||||||
else:
|
if self._sensor_name == "Tag Vibration":
|
||||||
return None
|
|
||||||
elif self._sensor_name == "Tag Vibration":
|
|
||||||
self._state =\
|
self._state =\
|
||||||
self._data.camera_data.moduleMotionDetected(self._home,
|
self._data.camera_data.moduleMotionDetected(self._home,
|
||||||
self._module_name,
|
self._module_name,
|
||||||
|
@ -9,6 +9,7 @@ import logging
|
|||||||
import requests
|
import requests
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.const import CONF_VERIFY_SSL
|
||||||
from homeassistant.components.netatmo import CameraData
|
from homeassistant.components.netatmo import CameraData
|
||||||
from homeassistant.components.camera import (Camera, PLATFORM_SCHEMA)
|
from homeassistant.components.camera import (Camera, PLATFORM_SCHEMA)
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
@ -22,6 +23,7 @@ CONF_HOME = 'home'
|
|||||||
CONF_CAMERAS = 'cameras'
|
CONF_CAMERAS = 'cameras'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
|
||||||
vol.Optional(CONF_HOME): cv.string,
|
vol.Optional(CONF_HOME): cv.string,
|
||||||
vol.Optional(CONF_CAMERAS, default=[]):
|
vol.Optional(CONF_CAMERAS, default=[]):
|
||||||
vol.All(cv.ensure_list, [cv.string]),
|
vol.All(cv.ensure_list, [cv.string]),
|
||||||
@ -33,6 +35,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
"""Setup access to Netatmo cameras."""
|
"""Setup access to Netatmo cameras."""
|
||||||
netatmo = get_component('netatmo')
|
netatmo = get_component('netatmo')
|
||||||
home = config.get(CONF_HOME)
|
home = config.get(CONF_HOME)
|
||||||
|
verify_ssl = config.get(CONF_VERIFY_SSL, True)
|
||||||
import lnetatmo
|
import lnetatmo
|
||||||
try:
|
try:
|
||||||
data = CameraData(netatmo.NETATMO_AUTH, home)
|
data = CameraData(netatmo.NETATMO_AUTH, home)
|
||||||
@ -42,7 +45,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
if config[CONF_CAMERAS] != [] and \
|
if config[CONF_CAMERAS] != [] and \
|
||||||
camera_name not in config[CONF_CAMERAS]:
|
camera_name not in config[CONF_CAMERAS]:
|
||||||
continue
|
continue
|
||||||
add_devices([NetatmoCamera(data, camera_name, home, camera_type)])
|
add_devices([NetatmoCamera(data, camera_name, home,
|
||||||
|
camera_type, verify_ssl)])
|
||||||
except lnetatmo.NoDevice:
|
except lnetatmo.NoDevice:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -50,11 +54,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
class NetatmoCamera(Camera):
|
class NetatmoCamera(Camera):
|
||||||
"""Representation of the images published from a Netatmo camera."""
|
"""Representation of the images published from a Netatmo camera."""
|
||||||
|
|
||||||
def __init__(self, data, camera_name, home, camera_type):
|
def __init__(self, data, camera_name, home, camera_type, verify_ssl):
|
||||||
"""Setup for access to the Netatmo camera images."""
|
"""Setup for access to the Netatmo camera images."""
|
||||||
super(NetatmoCamera, self).__init__()
|
super(NetatmoCamera, self).__init__()
|
||||||
self._data = data
|
self._data = data
|
||||||
self._camera_name = camera_name
|
self._camera_name = camera_name
|
||||||
|
self._verify_ssl = verify_ssl
|
||||||
if home:
|
if home:
|
||||||
self._name = home + ' / ' + camera_name
|
self._name = home + ' / ' + camera_name
|
||||||
else:
|
else:
|
||||||
@ -74,11 +79,17 @@ class NetatmoCamera(Camera):
|
|||||||
if self._localurl:
|
if self._localurl:
|
||||||
response = requests.get('{0}/live/snapshot_720.jpg'.format(
|
response = requests.get('{0}/live/snapshot_720.jpg'.format(
|
||||||
self._localurl), timeout=10)
|
self._localurl), timeout=10)
|
||||||
else:
|
elif self._vpnurl:
|
||||||
response = requests.get('{0}/live/snapshot_720.jpg'.format(
|
response = requests.get('{0}/live/snapshot_720.jpg'.format(
|
||||||
self._vpnurl), timeout=10)
|
self._vpnurl), timeout=10, verify=self._verify_ssl)
|
||||||
|
else:
|
||||||
|
_LOGGER.error('Welcome VPN url is None')
|
||||||
|
self._data.update()
|
||||||
|
(self._vpnurl, self._localurl) = \
|
||||||
|
self._data.camera_data.cameraUrls(camera=self._camera_name)
|
||||||
|
return None
|
||||||
except requests.exceptions.RequestException as error:
|
except requests.exceptions.RequestException as error:
|
||||||
_LOGGER.error('Welcome VPN url changed: %s', error)
|
_LOGGER.error('Welcome url changed: %s', error)
|
||||||
self._data.update()
|
self._data.update()
|
||||||
(self._vpnurl, self._localurl) = \
|
(self._vpnurl, self._localurl) = \
|
||||||
self._data.camera_data.cameraUrls(camera=self._camera_name)
|
self._data.camera_data.cameraUrls(camera=self._camera_name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user