Tibber component and notify (#17062)
* Refactor tibber, and Tibber notify * update Tibber lib. * tibber * Tibber coveragerc * Tibber upgrade lib * style * comments * use async_get_service * event
This commit is contained in:
parent
3abdf217bb
commit
05d8c57212
5 changed files with 103 additions and 21 deletions
|
@ -10,25 +10,15 @@ import logging
|
|||
|
||||
from datetime import timedelta
|
||||
import aiohttp
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, CONF_ACCESS_TOKEN
|
||||
from homeassistant.components.tibber import DOMAIN as TIBBER_DOMAIN
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
REQUIREMENTS = ['pyTibber==0.6.0']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_ACCESS_TOKEN): cv.string
|
||||
})
|
||||
|
||||
ICON = 'mdi:currency-usd'
|
||||
ICON_RT = 'mdi:power-plug'
|
||||
SCAN_INTERVAL = timedelta(minutes=1)
|
||||
|
@ -38,16 +28,14 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=5)
|
|||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the Tibber sensor."""
|
||||
import tibber
|
||||
tibber_connection = tibber.Tibber(config[CONF_ACCESS_TOKEN],
|
||||
websession=async_get_clientsession(hass))
|
||||
if discovery_info is None:
|
||||
_LOGGER.error("Tibber sensor configuration has changed."
|
||||
" Check https://home-assistant.io/components/tibber/")
|
||||
return
|
||||
|
||||
async def _close(*_):
|
||||
await tibber_connection.rt_disconnect()
|
||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _close)
|
||||
tibber_connection = hass.data.get(TIBBER_DOMAIN)
|
||||
|
||||
try:
|
||||
await tibber_connection.update_info()
|
||||
dev = []
|
||||
for home in tibber_connection.get_homes():
|
||||
await home.update_info()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue