core/homeassistant/components/ecoal_boiler.py

99 lines
3.5 KiB
Python
Raw Normal View History

Ecoal (esterownik.pl) static fuel boiler and pump controller (#18480) - matkor * Starting work on ecoal boiler controller iface. * Sending some values/states to controller. * Basic status parsing, and simple settings. * Platform configuration. * Temp sensors seems be working. * Switch from separate h/m/s to datetime. * Vocabulary updates. * secondary_central_heating_pump -> central_heating_pump2 * Pumps as switches. * Optional enabling pumps via config. * requests==2.20.1 added to REQUIREMENTS. * Optional enabling temp sensors from configuration yaml. * autopep8, black, pylint. * flake8. * pydocstyle * All style checkers again. * requests==2.20.1 required by homeassistant.components.sensor.ecoal_boiler. * Verify / set switches in update(). Code cleanup. * script/lint + travis issues. * Cleanup, imperative mood. * pylint, travis. * Updated .coveragerc. * Using configuration consts from homeassistant.const * typo. * Replace global ECOAL_CONTR with hass.data[DATA_ECOAL_BOILER]. Remove requests from REQUIREMENTS. * Killed .update()/reread_update() in Entities __init__()s. Removed debug/comments. * Removed debug/comments. * script/lint fixes. * script/gen_requirements_all.py run. * Travis fixes. * Configuration now validated. * Split controller code to separate package. * Replace in module docs with link to https://home-assistant.io . * Correct component module path in .coveragerc. More vals from const.py. Use dict[key] for required config keys. Check if credentials are correct during component setup. Renamed add_devices to add_entities. * Sensor/switch depends on ecoal_boiler component. EcoalSwitch inherits from SwitchDevice. Killed same as default should_poll(). Remove not neede schedule_update_ha_state() calls from turn_on/off. * lint fixes. * Move sensors/switches configuration to component setup. * Lint fixes. * Invalidating ecoal iface cache instead of force read in turn_on/off(). * Fail component setup before adding any platform entities. Kill NOTE. * Disallow setting entity names from config file, use code defined default names. * Rework configuration file to use monitored_conditions like in rainmachine component. * Killed pylint exception. Log error when connection to controller fails. * A few fixes. * Linted.
2019-01-22 13:14:27 +00:00
"""
Component to control ecoal/esterownik.pl coal/wood boiler controller.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/ecoal_boiler/
"""
import logging
import voluptuous as vol
from homeassistant.const import (CONF_HOST, CONF_PASSWORD, CONF_USERNAME,
CONF_MONITORED_CONDITIONS, CONF_SENSORS,
CONF_SWITCHES)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import load_platform
REQUIREMENTS = ['ecoaliface==0.4.0']
_LOGGER = logging.getLogger(__name__)
DOMAIN = "ecoal_boiler"
DATA_ECOAL_BOILER = 'data_' + DOMAIN
DEFAULT_USERNAME = "admin"
DEFAULT_PASSWORD = "admin"
# Available pump ids with assigned HA names
# Available as switches
AVAILABLE_PUMPS = {
"central_heating_pump": "Central heating pump",
"central_heating_pump2": "Central heating pump2",
"domestic_hot_water_pump": "Domestic hot water pump",
}
# Available temp sensor ids with assigned HA names
# Available as sensors
AVAILABLE_SENSORS = {
"outdoor_temp": 'Outdoor temperature',
"indoor_temp": 'Indoor temperature',
"indoor2_temp": 'Indoor temperature 2',
"domestic_hot_water_temp": 'Domestic hot water temperature',
"target_domestic_hot_water_temp": 'Target hot water temperature',
"feedwater_in_temp": 'Feedwater input temperature',
"feedwater_out_temp": 'Feedwater output temperature',
"target_feedwater_temp": 'Target feedwater temperature',
"fuel_feeder_temp": 'Fuel feeder temperature',
"exhaust_temp": 'Exhaust temperature',
}
SWITCH_SCHEMA = vol.Schema({
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(AVAILABLE_PUMPS)):
vol.All(cv.ensure_list, [vol.In(AVAILABLE_PUMPS)])
})
SENSOR_SCHEMA = vol.Schema({
vol.Optional(CONF_MONITORED_CONDITIONS, default=list(AVAILABLE_SENSORS)):
vol.All(cv.ensure_list, [vol.In(AVAILABLE_SENSORS)])
})
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_USERNAME,
default=DEFAULT_USERNAME): cv.string,
vol.Optional(CONF_PASSWORD,
default=DEFAULT_PASSWORD): cv.string,
vol.Optional(CONF_SWITCHES, default={}): SWITCH_SCHEMA,
vol.Optional(CONF_SENSORS, default={}): SENSOR_SCHEMA,
})
}, extra=vol.ALLOW_EXTRA)
def setup(hass, hass_config):
"""Set up global ECoalController instance same for sensors and switches."""
from ecoaliface.simple import ECoalController
conf = hass_config[DOMAIN]
host = conf[CONF_HOST]
username = conf[CONF_USERNAME]
passwd = conf[CONF_PASSWORD]
# Creating ECoalController instance makes HTTP request to controller.
ecoal_contr = ECoalController(host, username, passwd)
if ecoal_contr.version is None:
# Wrong credentials nor network config
_LOGGER.error("Unable to read controller status from %s@%s"
" (wrong host/credentials)", username, host, )
return False
_LOGGER.debug("Detected controller version: %r @%s",
ecoal_contr.version, host, )
hass.data[DATA_ECOAL_BOILER] = ecoal_contr
# Setup switches
switches = conf[CONF_SWITCHES][CONF_MONITORED_CONDITIONS]
load_platform(hass, 'switch', DOMAIN, switches, hass_config)
# Setup temp sensors
sensors = conf[CONF_SENSORS][CONF_MONITORED_CONDITIONS]
load_platform(hass, 'sensor', DOMAIN, sensors, hass_config)
return True