mirror of
https://github.com/home-assistant/core.git
synced 2025-05-14 02:49:15 +00:00

* Added error handling for sense API timeouts * Moved imports in function * Moved imports to more appropriate function * Change exception to custom package version * Updated sense_energy library to 0.4.2 * Added binary sensors for individual devices * Whitespace updates * Split into component, sensors, binary sensors * Fixed whitespace * Fixed whitespace * Moved time constant into sensor file * Regenerated requirements * Fixed whitespace * Updated component dependency * Fixed whitespace * Code cleanup * High and low target temps are also supported if target is supported * Revert "High and low target temps are also supported if target is supported" This reverts commit 66b33dc2b81ce81a84553fff327575a0e36d3c8d. * Added all sense components to .coveragerc * Added check authentication exception * binary/sensor platforms loaded in setup * Changed to add all detected devices * Changed to add all sensors on setup * Code cleanup * Whitespace * Whitespace * Added sense as requirement for platform * pylint fixes * Whitespace * Switched requirement to dependency * Made non-class function * Whitespace * Removed unneeded checks * Increased API delay to 60 seconds * Added guard clause for discovery_info * Tidy code * Whitespace
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
"""
|
|
Support for monitoring a Sense energy sensor.
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
https://home-assistant.io/components/sense/
|
|
"""
|
|
import logging
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.helpers.discovery import load_platform
|
|
from homeassistant.const import (CONF_EMAIL, CONF_PASSWORD, CONF_TIMEOUT)
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
REQUIREMENTS = ['sense_energy==0.5.1']
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
SENSE_DATA = 'sense_data'
|
|
|
|
DOMAIN = 'sense'
|
|
|
|
ACTIVE_UPDATE_RATE = 60
|
|
DEFAULT_TIMEOUT = 5
|
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
|
DOMAIN: vol.Schema({
|
|
vol.Required(CONF_EMAIL): cv.string,
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
vol.Optional(CONF_TIMEOUT, DEFAULT_TIMEOUT): cv.positive_int,
|
|
})
|
|
}, extra=vol.ALLOW_EXTRA)
|
|
|
|
|
|
def setup(hass, config):
|
|
"""Set up the Sense sensor."""
|
|
from sense_energy import Senseable, SenseAuthenticationException
|
|
|
|
username = config[DOMAIN][CONF_EMAIL]
|
|
password = config[DOMAIN][CONF_PASSWORD]
|
|
|
|
timeout = config[DOMAIN][CONF_TIMEOUT]
|
|
try:
|
|
hass.data[SENSE_DATA] = Senseable(api_timeout=timeout,
|
|
wss_timeout=timeout)
|
|
hass.data[SENSE_DATA].authenticate(username, password)
|
|
hass.data[SENSE_DATA].rate_limit = ACTIVE_UPDATE_RATE
|
|
except SenseAuthenticationException:
|
|
_LOGGER.error("Could not authenticate with sense server")
|
|
return False
|
|
load_platform(hass, 'sensor', DOMAIN, {}, config)
|
|
load_platform(hass, 'binary_sensor', DOMAIN, {}, config)
|
|
return True
|