mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add voluptuous to efergy. (#2943)
This commit is contained in:
parent
9fcfc213c7
commit
dfca2476bd
@ -5,40 +5,60 @@ For more details about this platform, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/sensor.efergy/
|
https://home-assistant.io/components/sensor.efergy/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from requests import RequestException, get
|
from requests import RequestException, get
|
||||||
|
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
_RESOURCE = 'https://engage.efergy.com/mobile_proxy/'
|
_RESOURCE = 'https://engage.efergy.com/mobile_proxy/'
|
||||||
|
|
||||||
|
CONF_APPTOKEN = 'app_token'
|
||||||
|
CONF_UTC_OFFSET = 'utc_offset'
|
||||||
|
CONF_MONITORED_VARIABLES = 'monitored_variables'
|
||||||
|
CONF_SENSOR_TYPE = 'type'
|
||||||
|
|
||||||
|
CONF_CURRENCY = 'currency'
|
||||||
|
CONF_PERIOD = 'period'
|
||||||
|
|
||||||
|
CONF_INSTANT = 'instant_readings'
|
||||||
|
CONF_BUDGET = 'budget'
|
||||||
|
CONF_COST = 'cost'
|
||||||
|
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
'instant_readings': ['Energy Usage', 'kW'],
|
CONF_INSTANT: ['Energy Usage', 'kW'],
|
||||||
'budget': ['Energy Budget', None],
|
CONF_BUDGET: ['Energy Budget', None],
|
||||||
'cost': ['Energy Cost', None],
|
CONF_COST: ['Energy Cost', None],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TYPES_SCHEMA = vol.In(
|
||||||
|
[CONF_INSTANT, CONF_BUDGET, CONF_COST])
|
||||||
|
|
||||||
|
SENSORS_SCHEMA = vol.Schema({
|
||||||
|
vol.Required(CONF_SENSOR_TYPE): TYPES_SCHEMA,
|
||||||
|
vol.Optional(CONF_CURRENCY, default=''): cv.string,
|
||||||
|
vol.Optional(CONF_PERIOD, default='year'): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_APPTOKEN): cv.string,
|
||||||
|
vol.Optional(CONF_UTC_OFFSET): cv.string,
|
||||||
|
vol.Required(CONF_MONITORED_VARIABLES): [SENSORS_SCHEMA]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Efergy sensor."""
|
"""Setup the Efergy sensor."""
|
||||||
app_token = config.get("app_token")
|
app_token = config.get(CONF_APPTOKEN)
|
||||||
if not app_token:
|
utc_offset = str(config.get(CONF_UTC_OFFSET))
|
||||||
_LOGGER.error(
|
|
||||||
"Configuration Error"
|
|
||||||
"Please make sure you have configured your app token")
|
|
||||||
return None
|
|
||||||
utc_offset = str(config.get("utc_offset"))
|
|
||||||
dev = []
|
dev = []
|
||||||
for variable in config['monitored_variables']:
|
for variable in config[CONF_MONITORED_VARIABLES]:
|
||||||
if 'period' not in variable:
|
dev.append(EfergySensor(
|
||||||
variable['period'] = ''
|
variable[CONF_SENSOR_TYPE], app_token, utc_offset,
|
||||||
if 'currency' not in variable:
|
variable[CONF_PERIOD], variable[CONF_CURRENCY]))
|
||||||
variable['currency'] = ''
|
|
||||||
if variable['type'] not in SENSOR_TYPES:
|
|
||||||
_LOGGER.error('Sensor type: "%s" does not exist', variable)
|
|
||||||
else:
|
|
||||||
dev.append(EfergySensor(variable['type'], app_token, utc_offset,
|
|
||||||
variable['period'], variable['currency']))
|
|
||||||
|
|
||||||
add_devices(dev)
|
add_devices(dev)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user