-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Version 2.0.0 * Update README.md * Update hacs.json * Update labels.yml * Update manifest.json * Create config_flow.py * Update hacs.json * Update release.yml * Update labels.yml * Update README.md * Create logo_new@2x.png * Update README.md * Update .gitignore * Update README.md * Delete entity.py * Update __init__.py * Update manifest.json * Create entitys.py * Update __init__.py * Update const.py * Update manifest.json * Create const_schema.py * Update config_flow.py * Update sensor.py * Create en.json * Create de.json * Update sensor.py * Create strings.json * Update sensor.py * Update release.yml * Update config_flow.py * Update const.py * Update config_flow.py * Create coordinator.py * Update manifest.json * Update const_schema.py * Create account_de_url.json * Create demo_de_url.json * Update config_flow.py * Update hacs.json
- Loading branch information
Showing
20 changed files
with
1,221 additions
and
554 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,3 +133,6 @@ dmypy.json | |
|
||
# Home Assistant Core | ||
/homeassistant | ||
|
||
# Dev Files | ||
codiga.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,78 @@ | ||
""" ecotrend-ista """ | ||
""" ista EcoTrend Version 2 """ | ||
from __future__ import annotations | ||
|
||
import logging | ||
import voluptuous as vol | ||
|
||
from datetime import timedelta | ||
import voluptuous as vol | ||
|
||
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN | ||
from homeassistant.const import CONF_SCAN_INTERVAL | ||
from homeassistant import config_entries | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import discovery | ||
import homeassistant.helpers.config_validation as cv | ||
from homeassistant.helpers.typing import ConfigType | ||
|
||
from .const import ( | ||
CONF_CONTROLLER, | ||
CONF_EMAIL, | ||
CONF_PASSWORD, | ||
CONF_UNIT, | ||
CONF_UNIT_HEATING, | ||
CONF_UNIT_WARMWATER, | ||
CONF_UPDATE_FREQUENCY, | ||
CONF_YEAR, | ||
CONF_YEARMONTH, | ||
DEFAULT_SCAN_INTERVAL_TIME, | ||
DOMAIN, | ||
UNIT_SUPPORT_HEATING, | ||
UNIT_SUPPORT_WARMWATER, | ||
) | ||
from .const import DATA_HASS_CONFIG, DOMAIN | ||
from .const_schema import DEFAULT_DATA_SCHEMA | ||
from .coordinator import IstaDataUpdateCoordinator | ||
|
||
from pyecotrend_ista import pyecotrend_ista as ista | ||
PLATFORMS = [Platform.SENSOR] | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
PLATFORMS = [SENSOR_DOMAIN] | ||
DEFAULT_SCAN_INTERVAL = timedelta(seconds=DEFAULT_SCAN_INTERVAL_TIME) | ||
|
||
CONTROLLER_SCHEMA = vol.Schema( | ||
{ | ||
vol.Required(CONF_EMAIL): cv.string, | ||
vol.Required(CONF_PASSWORD): cv.string, | ||
############################################## | ||
########## deprecated configuration ########## | ||
############################################## | ||
########## options v1.0.7-beta-3 ############# | ||
vol.Remove(CONF_UNIT): cv.string, ########### | ||
############################################## | ||
vol.Optional(CONF_UNIT_HEATING, default="kwh"): cv.string, | ||
vol.Optional(CONF_UNIT_WARMWATER, default="kwh"): cv.string, | ||
vol.Optional(CONF_YEAR, default=[]): cv.ensure_list, | ||
vol.Optional(CONF_YEARMONTH, default=[]): cv.ensure_list, | ||
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL): cv.time_period, | ||
} | ||
) | ||
|
||
CONFIG_SCHEMA = vol.Schema( | ||
{DOMAIN: vol.Schema(vol.All(cv.ensure_list, [CONTROLLER_SCHEMA]))}, | ||
{DOMAIN: vol.Schema(DEFAULT_DATA_SCHEMA)}, | ||
extra=vol.ALLOW_EXTRA, | ||
) | ||
|
||
|
||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: | ||
hass.data[CONF_EMAIL] = [] | ||
hass.data[CONF_PASSWORD] = [] | ||
hass.data[CONF_UNIT_HEATING] = [] | ||
hass.data[CONF_UNIT_WARMWATER] = [] | ||
hass.data[CONF_UPDATE_FREQUENCY] = [] | ||
hass.data[CONF_YEAR] = [] | ||
hass.data[CONF_YEARMONTH] = [] | ||
hass.data[DOMAIN] = [] | ||
success = False | ||
for controller_config in config[DOMAIN]: | ||
success = success or await _setup_controller(hass, controller_config, config) | ||
return success | ||
|
||
|
||
async def _setup_controller(hass: HomeAssistant, controller_config, config: ConfigType) -> bool: | ||
email: str = controller_config[CONF_EMAIL] | ||
password: str = controller_config[CONF_PASSWORD] | ||
unitheating = controller_config[CONF_UNIT_HEATING] | ||
unitwarmwater = controller_config[CONF_UNIT_WARMWATER] | ||
|
||
if unitheating != "" and unitheating not in UNIT_SUPPORT_HEATING: | ||
raise Exception(f'unit "{unitheating}" don\'t supported. Only: {UNIT_SUPPORT_HEATING} or remove unit: "{unitheating}"') | ||
if unitwarmwater != "" and unitwarmwater not in UNIT_SUPPORT_WARMWATER: | ||
raise Exception( | ||
f'unit "{unitwarmwater}" don\'t supported. Only: {UNIT_SUPPORT_WARMWATER} or remove unit: "{unitwarmwater}"' | ||
) | ||
|
||
eco = ista.PyEcotrendIsta(email=email, password=password) | ||
await eco.login() | ||
position = len(hass.data[DOMAIN]) | ||
hass.data[CONF_EMAIL].append(email) | ||
hass.data[CONF_PASSWORD].append(password) | ||
hass.data[CONF_UNIT_HEATING].append(unitheating) | ||
hass.data[CONF_UNIT_WARMWATER].append(unitwarmwater) | ||
hass.data[CONF_UPDATE_FREQUENCY].append(controller_config[CONF_SCAN_INTERVAL]) | ||
hass.data[CONF_YEAR].append(controller_config[CONF_YEAR]) | ||
hass.data[CONF_YEARMONTH].append(controller_config[CONF_YEARMONTH]) | ||
hass.data[DOMAIN].append(eco) | ||
|
||
for platform in PLATFORMS: | ||
async def async_setup(hass: HomeAssistant, hass_config: ConfigType) -> bool: | ||
"""Set up the ista EcoTrend Version 2 component.""" | ||
_LOGGER.debug("Set up the ista EcoTrend Version 2 component") | ||
hass.data.setdefault(DOMAIN, {}) | ||
hass.data[DOMAIN][DATA_HASS_CONFIG] = hass_config | ||
if DOMAIN in hass_config: | ||
hass.async_create_task( | ||
discovery.async_load_platform( | ||
hass, | ||
platform, | ||
hass.config_entries.flow.async_init( | ||
DOMAIN, | ||
{CONF_CONTROLLER: position, **controller_config}, | ||
config, | ||
context={"source": config_entries.SOURCE_IMPORT}, | ||
data={ | ||
CONF_EMAIL: hass_config[DOMAIN][CONF_EMAIL], | ||
CONF_PASSWORD: hass_config[DOMAIN][CONF_PASSWORD], | ||
}, | ||
) | ||
) | ||
return True | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Configure based on config entry.""" | ||
_LOGGER.debug("Configure based on config entry %s", entry.entry_id) | ||
coordinator = IstaDataUpdateCoordinator(hass, entry) | ||
await coordinator.init() | ||
await coordinator.async_config_entry_first_refresh() | ||
|
||
hass.data.setdefault(DOMAIN, {}) | ||
hass.data[DOMAIN][entry.entry_id] = coordinator | ||
|
||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
||
entry.async_on_unload(entry.add_update_listener(options_update_listener)) | ||
|
||
return True | ||
|
||
|
||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Unload a config entry.""" | ||
_LOGGER.debug("Unload a config entry") | ||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
|
||
if unload_ok: | ||
hass.data[DOMAIN].pop(entry.entry_id) | ||
return unload_ok | ||
|
||
|
||
async def options_update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> None: | ||
"""Handle options update.""" | ||
_LOGGER.debug("Configuration options updated, reloading ista EcoTrend 2 integration") | ||
await hass.config_entries.async_reload(config_entry.entry_id) |
Oops, something went wrong.