Used Interface for configuration

This commit is contained in:
dotKrad
2019-12-17 23:23:59 -05:00
parent adea133b3d
commit 0aedb1df2d
19 changed files with 105 additions and 755 deletions

View File

@@ -6,6 +6,9 @@ import asyncio
from homeassistant.helpers.entity import Entity
from homeassistant import util
from homeassistant.const import CONF_NAME, EVENT_CORE_CONFIG_UPDATE
from .const import DOMAIN, ICON
MIN_TIME_BETWEEN_SCANS = timedelta(minutes=1440)
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1440)
@@ -19,24 +22,47 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
add_devices([FplSensor(hass, config)])
async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities([FplSensor(hass, config_entry.data)])
class FplSensor(Entity):
def __init__(self, hass, config):
print("init")
self._config = config
self.username = config.get(const.CONF_USERNAME)
self.password = config.get(const.CONF_PASSWORD)
self._state = 0
self.loop = hass.loop
self.api = None
async def _core_config_updated(self, _event):
"""Handle core config updated."""
print("Core config updated")
# self._init_data()
# if self._unsub_fetch_data:
# self._unsub_fetch_data()
# self._unsub_fetch_data = None
# await self._fetch_data()
async def async_added_to_hass(self):
await self.async_update()
@property
def name(self):
"""Returns the name of the sensor."""
return "fpl"
name = self._config.get(CONF_NAME)
if name is not None:
return f"{DOMAIN.upper()} {name}"
return DOMAIN
@property
def state(self):
return self._state
@property
def icon(self):
return ICON
@property
def state_attributes(self):
return {