Use voluptuous for netatmo (#3287)
* Migrate to voluptuous * Switch back to archive (reverting #3285)
This commit is contained in:
parent
05a3b610ff
commit
515c4773f3
3 changed files with 67 additions and 54 deletions
|
@ -6,46 +6,48 @@ https://home-assistant.io/components/netatmo/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from urllib.error import HTTPError
|
from urllib.error import HTTPError
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_API_KEY, CONF_PASSWORD, CONF_USERNAME)
|
CONF_API_KEY, CONF_PASSWORD, CONF_USERNAME)
|
||||||
from homeassistant.helpers import validate_config, discovery
|
from homeassistant.helpers import discovery
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = [
|
REQUIREMENTS = [
|
||||||
'https://github.com/jabesq/netatmo-api-python/archive/'
|
'https://github.com/jabesq/netatmo-api-python/archive/'
|
||||||
'master.zip#lnetatmo==0.5.0']
|
'v0.5.0.zip#lnetatmo==0.5.0']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF_SECRET_KEY = 'secret_key'
|
CONF_SECRET_KEY = 'secret_key'
|
||||||
|
|
||||||
DOMAIN = 'netatmo'
|
DOMAIN = 'netatmo'
|
||||||
|
|
||||||
NETATMO_AUTH = None
|
NETATMO_AUTH = None
|
||||||
|
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
"""Setup the Netatmo devices."""
|
"""Setup the Netatmo devices."""
|
||||||
if not validate_config(config,
|
|
||||||
{DOMAIN: [CONF_API_KEY,
|
|
||||||
CONF_USERNAME,
|
|
||||||
CONF_PASSWORD,
|
|
||||||
CONF_SECRET_KEY]},
|
|
||||||
_LOGGER):
|
|
||||||
return None
|
|
||||||
|
|
||||||
import lnetatmo
|
import lnetatmo
|
||||||
|
|
||||||
global NETATMO_AUTH
|
global NETATMO_AUTH
|
||||||
try:
|
try:
|
||||||
NETATMO_AUTH = lnetatmo.ClientAuth(config[DOMAIN][CONF_API_KEY],
|
NETATMO_AUTH = lnetatmo.ClientAuth(
|
||||||
config[DOMAIN][CONF_SECRET_KEY],
|
config[DOMAIN][CONF_API_KEY], config[DOMAIN][CONF_SECRET_KEY],
|
||||||
config[DOMAIN][CONF_USERNAME],
|
config[DOMAIN][CONF_USERNAME], config[DOMAIN][CONF_PASSWORD],
|
||||||
config[DOMAIN][CONF_PASSWORD],
|
'read_station read_camera access_camera')
|
||||||
"read_station read_camera "
|
|
||||||
"access_camera")
|
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
_LOGGER.error(
|
_LOGGER.error("Unable to connect to NatAtmo API")
|
||||||
"Connection error "
|
|
||||||
"Please check your settings for NatAtmo API.")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for component in 'camera', 'sensor':
|
for component in 'camera', 'sensor':
|
||||||
|
|
|
@ -6,44 +6,59 @@ https://home-assistant.io/components/sensor.netatmo/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import TEMP_CELSIUS
|
from homeassistant.const import TEMP_CELSIUS
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
DEPENDENCIES = ["netatmo"]
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SENSOR_TYPES = {
|
|
||||||
'temperature': ['Temperature', TEMP_CELSIUS, 'mdi:thermometer'],
|
|
||||||
'co2': ['CO2', 'ppm', 'mdi:cloud'],
|
|
||||||
'pressure': ['Pressure', 'mbar', 'mdi:gauge'],
|
|
||||||
'noise': ['Noise', 'dB', 'mdi:volume-high'],
|
|
||||||
'humidity': ['Humidity', '%', 'mdi:water-percent'],
|
|
||||||
'rain': ['Rain', 'mm', 'mdi:weather-rainy'],
|
|
||||||
'sum_rain_1': ['sum_rain_1', 'mm', 'mdi:weather-rainy'],
|
|
||||||
'sum_rain_24': ['sum_rain_24', 'mm', 'mdi:weather-rainy'],
|
|
||||||
'battery_vp': ['Battery', '', 'mdi:battery'],
|
|
||||||
'min_temp': ['Min Temp.', TEMP_CELSIUS, 'mdi:thermometer'],
|
|
||||||
'max_temp': ['Max Temp.', TEMP_CELSIUS, 'mdi:thermometer'],
|
|
||||||
'WindAngle': ['Angle', '', 'mdi:compass'],
|
|
||||||
'WindStrength': ['Strength', 'km/h', 'mdi:weather-windy'],
|
|
||||||
'GustAngle': ['Gust Angle', '', 'mdi:compass'],
|
|
||||||
'GustStrength': ['Gust Strength', 'km/h', 'mdi:weather-windy'],
|
|
||||||
'rf_status': ['Radio', '', 'mdi:signal'],
|
|
||||||
'wifi_status': ['Wifi', '', 'mdi:wifi']
|
|
||||||
}
|
|
||||||
|
|
||||||
CONF_STATION = 'station'
|
|
||||||
ATTR_MODULE = 'modules'
|
ATTR_MODULE = 'modules'
|
||||||
|
|
||||||
# Return cached results if last scan was less then this time ago
|
CONF_MODULES = 'modules'
|
||||||
# NetAtmo Data is uploaded to server every 10mn
|
CONF_MODULE_NAME = 'module_name'
|
||||||
# so this time should not be under
|
CONF_STATION = 'station'
|
||||||
|
|
||||||
|
DEPENDENCIES = ['netatmo']
|
||||||
|
|
||||||
|
# NetAtmo Data is uploaded to server every 10 minutes
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600)
|
||||||
|
|
||||||
|
SENSOR_TYPES = {
|
||||||
|
'temperature': ['Temperature', TEMP_CELSIUS, 'mdi:thermometer'],
|
||||||
|
'co2': ['CO2', 'ppm', 'mdi:cloud'],
|
||||||
|
'pressure': ['Pressure', 'mbar', 'mdi:gauge'],
|
||||||
|
'noise': ['Noise', 'dB', 'mdi:volume-high'],
|
||||||
|
'humidity': ['Humidity', '%', 'mdi:water-percent'],
|
||||||
|
'rain': ['Rain', 'mm', 'mdi:weather-rainy'],
|
||||||
|
'sum_rain_1': ['sum_rain_1', 'mm', 'mdi:weather-rainy'],
|
||||||
|
'sum_rain_24': ['sum_rain_24', 'mm', 'mdi:weather-rainy'],
|
||||||
|
'battery_vp': ['Battery', '', 'mdi:battery'],
|
||||||
|
'min_temp': ['Min Temp.', TEMP_CELSIUS, 'mdi:thermometer'],
|
||||||
|
'max_temp': ['Max Temp.', TEMP_CELSIUS, 'mdi:thermometer'],
|
||||||
|
'WindAngle': ['Angle', '', 'mdi:compass'],
|
||||||
|
'WindStrength': ['Strength', 'km/h', 'mdi:weather-windy'],
|
||||||
|
'GustAngle': ['Gust Angle', '', 'mdi:compass'],
|
||||||
|
'GustStrength': ['Gust Strength', 'km/h', 'mdi:weather-windy'],
|
||||||
|
'rf_status': ['Radio', '', 'mdi:signal'],
|
||||||
|
'wifi_status': ['Wifi', '', 'mdi:wifi']
|
||||||
|
}
|
||||||
|
|
||||||
|
MODULE_SCHEMA = vol.Schema({
|
||||||
|
vol.Required(CONF_MODULE_NAME, default=[]):
|
||||||
|
vol.All(cv.ensure_list, [vol.In(SENSOR_TYPES)]),
|
||||||
|
})
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Optional(CONF_STATION): cv.string,
|
||||||
|
vol.Required(CONF_MODULES): MODULE_SCHEMA,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the available Netatmo weather sensors."""
|
"""Setup the available Netatmo weather sensors."""
|
||||||
|
@ -53,18 +68,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
dev = []
|
dev = []
|
||||||
try:
|
try:
|
||||||
# Iterate each module
|
# Iterate each module
|
||||||
for module_name, monitored_conditions in config[ATTR_MODULE].items():
|
for module_name, monitored_conditions in config[CONF_MODULES].items():
|
||||||
# Test if module exist """
|
# Test if module exist """
|
||||||
if module_name not in data.get_module_names():
|
if module_name not in data.get_module_names():
|
||||||
_LOGGER.error('Module name: "%s" not found', module_name)
|
_LOGGER.error('Module name: "%s" not found', module_name)
|
||||||
continue
|
continue
|
||||||
# Only create sensor for monitored """
|
# Only create sensor for monitored """
|
||||||
for variable in monitored_conditions:
|
for variable in monitored_conditions:
|
||||||
if variable not in SENSOR_TYPES:
|
dev.append(NetAtmoSensor(data, module_name, variable))
|
||||||
_LOGGER.error('Sensor type: "%s" does not exist', variable)
|
|
||||||
else:
|
|
||||||
dev.append(
|
|
||||||
NetAtmoSensor(data, module_name, variable))
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -77,7 +88,7 @@ class NetAtmoSensor(Entity):
|
||||||
|
|
||||||
def __init__(self, netatmo_data, module_name, sensor_type):
|
def __init__(self, netatmo_data, module_name, sensor_type):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self._name = "NetAtmo {} {}".format(module_name,
|
self._name = 'NetAtmo {} {}'.format(module_name,
|
||||||
SENSOR_TYPES[sensor_type][0])
|
SENSOR_TYPES[sensor_type][0])
|
||||||
self.netatmo_data = netatmo_data
|
self.netatmo_data = netatmo_data
|
||||||
self.module_name = module_name
|
self.module_name = module_name
|
||||||
|
|
|
@ -164,7 +164,7 @@ https://github.com/danieljkemp/onkyo-eiscp/archive/python3.zip#onkyo-eiscp==0.9.
|
||||||
https://github.com/gadgetreactor/pyHS100/archive/master.zip#pyHS100==0.1.2
|
https://github.com/gadgetreactor/pyHS100/archive/master.zip#pyHS100==0.1.2
|
||||||
|
|
||||||
# homeassistant.components.netatmo
|
# homeassistant.components.netatmo
|
||||||
https://github.com/jabesq/netatmo-api-python/archive/master.zip#lnetatmo==0.5.0
|
https://github.com/jabesq/netatmo-api-python/archive/v0.5.0.zip#lnetatmo==0.5.0
|
||||||
|
|
||||||
# homeassistant.components.sensor.sabnzbd
|
# homeassistant.components.sensor.sabnzbd
|
||||||
https://github.com/jamespcole/home-assistant-nzb-clients/archive/616cad59154092599278661af17e2a9f2cf5e2a9.zip#python-sabnzbd==0.1
|
https://github.com/jamespcole/home-assistant-nzb-clients/archive/616cad59154092599278661af17e2a9f2cf5e2a9.zip#python-sabnzbd==0.1
|
||||||
|
|
Loading…
Add table
Reference in a new issue