core/homeassistant/components/ecoal_boiler/sensor.py

50 lines
1.7 KiB
Python
Raw Normal View History

"""Allows reading temperatures from ecoal/esterownik.pl controller."""
from __future__ import annotations
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.const import UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
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
from . import AVAILABLE_SENSORS, DATA_ECOAL_BOILER
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
def setup_platform(
hass: HomeAssistant,
config: ConfigType,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
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
"""Set up the ecoal sensors."""
if discovery_info is None:
return
devices = []
ecoal_contr = hass.data[DATA_ECOAL_BOILER]
for sensor_id in discovery_info:
name = AVAILABLE_SENSORS[sensor_id]
devices.append(EcoalTempSensor(ecoal_contr, name, sensor_id))
add_entities(devices, True)
class EcoalTempSensor(SensorEntity):
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
"""Representation of a temperature sensor using ecoal status data."""
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
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
def __init__(self, ecoal_contr, name, status_attr):
"""Initialize the sensor."""
self._ecoal_contr = ecoal_contr
self._attr_name = name
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
self._status_attr = status_attr
2022-08-20 05:52:55 +00:00
def update(self) -> None:
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
"""Fetch new state data for the sensor.
This is the only method that should fetch new data for Home Assistant.
"""
# Old values read 0.5 back can still be used
status = self._ecoal_contr.get_cached_status()
self._attr_native_value = getattr(status, self._status_attr)