mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use shorthand attributes in Opentherm gateway (#99630)
This commit is contained in:
parent
c567a2c3d4
commit
94aec3e590
@ -52,6 +52,7 @@ class OpenThermBinarySensor(BinarySensorEntity):
|
|||||||
"""Represent an OpenTherm Gateway binary sensor."""
|
"""Represent an OpenTherm Gateway binary sensor."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
_attr_entity_registry_enabled_default = False
|
||||||
|
|
||||||
def __init__(self, gw_dev, var, source, device_class, friendly_name_format):
|
def __init__(self, gw_dev, var, source, device_class, friendly_name_format):
|
||||||
"""Initialize the binary sensor."""
|
"""Initialize the binary sensor."""
|
||||||
@ -61,73 +62,42 @@ class OpenThermBinarySensor(BinarySensorEntity):
|
|||||||
self._gateway = gw_dev
|
self._gateway = gw_dev
|
||||||
self._var = var
|
self._var = var
|
||||||
self._source = source
|
self._source = source
|
||||||
self._state = None
|
self._attr_device_class = device_class
|
||||||
self._device_class = device_class
|
|
||||||
if TRANSLATE_SOURCE[source] is not None:
|
if TRANSLATE_SOURCE[source] is not None:
|
||||||
friendly_name_format = (
|
friendly_name_format = (
|
||||||
f"{friendly_name_format} ({TRANSLATE_SOURCE[source]})"
|
f"{friendly_name_format} ({TRANSLATE_SOURCE[source]})"
|
||||||
)
|
)
|
||||||
self._friendly_name = friendly_name_format.format(gw_dev.name)
|
self._attr_name = friendly_name_format.format(gw_dev.name)
|
||||||
self._unsub_updates = None
|
self._unsub_updates = None
|
||||||
|
self._attr_unique_id = f"{gw_dev.gw_id}-{source}-{var}"
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, gw_dev.gw_id)},
|
||||||
|
manufacturer="Schelte Bron",
|
||||||
|
model="OpenTherm Gateway",
|
||||||
|
name=gw_dev.name,
|
||||||
|
sw_version=gw_dev.gw_version,
|
||||||
|
)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to updates from the component."""
|
"""Subscribe to updates from the component."""
|
||||||
_LOGGER.debug("Added OpenTherm Gateway binary sensor %s", self._friendly_name)
|
_LOGGER.debug("Added OpenTherm Gateway binary sensor %s", self._attr_name)
|
||||||
self._unsub_updates = async_dispatcher_connect(
|
self._unsub_updates = async_dispatcher_connect(
|
||||||
self.hass, self._gateway.update_signal, self.receive_report
|
self.hass, self._gateway.update_signal, self.receive_report
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self) -> None:
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
"""Unsubscribe from updates from the component."""
|
"""Unsubscribe from updates from the component."""
|
||||||
_LOGGER.debug(
|
_LOGGER.debug("Removing OpenTherm Gateway binary sensor %s", self._attr_name)
|
||||||
"Removing OpenTherm Gateway binary sensor %s", self._friendly_name
|
|
||||||
)
|
|
||||||
self._unsub_updates()
|
self._unsub_updates()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Return availability of the sensor."""
|
"""Return availability of the sensor."""
|
||||||
return self._state is not None
|
return self._attr_is_on is not None
|
||||||
|
|
||||||
@property
|
|
||||||
def entity_registry_enabled_default(self):
|
|
||||||
"""Disable binary_sensors by default."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def receive_report(self, status):
|
def receive_report(self, status):
|
||||||
"""Handle status updates from the component."""
|
"""Handle status updates from the component."""
|
||||||
state = status[self._source].get(self._var)
|
state = status[self._source].get(self._var)
|
||||||
self._state = None if state is None else bool(state)
|
self._attr_is_on = None if state is None else bool(state)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the friendly name."""
|
|
||||||
return self._friendly_name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return device info."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._gateway.gw_id)},
|
|
||||||
manufacturer="Schelte Bron",
|
|
||||||
model="OpenTherm Gateway",
|
|
||||||
name=self._gateway.name,
|
|
||||||
sw_version=self._gateway.gw_version,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique ID."""
|
|
||||||
return f"{self._gateway.gw_id}-{self._source}-{self._var}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
"""Return true if the binary sensor is on."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the class of this device."""
|
|
||||||
return self._device_class
|
|
||||||
|
@ -70,6 +70,20 @@ class OpenThermClimate(ClimateEntity):
|
|||||||
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
|
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
|
||||||
)
|
)
|
||||||
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||||
|
_attr_available = False
|
||||||
|
_attr_hvac_modes = []
|
||||||
|
_attr_preset_modes = []
|
||||||
|
_attr_min_temp = 1
|
||||||
|
_attr_max_temp = 30
|
||||||
|
_hvac_mode = HVACMode.HEAT
|
||||||
|
_current_temperature: float | None = None
|
||||||
|
_new_target_temperature: float | None = None
|
||||||
|
_target_temperature: float | None = None
|
||||||
|
_away_mode_a: int | None = None
|
||||||
|
_away_mode_b: int | None = None
|
||||||
|
_away_state_a = False
|
||||||
|
_away_state_b = False
|
||||||
|
_current_operation: HVACAction | None = None
|
||||||
|
|
||||||
def __init__(self, gw_dev, options):
|
def __init__(self, gw_dev, options):
|
||||||
"""Initialize the device."""
|
"""Initialize the device."""
|
||||||
@ -78,22 +92,21 @@ class OpenThermClimate(ClimateEntity):
|
|||||||
ENTITY_ID_FORMAT, gw_dev.gw_id, hass=gw_dev.hass
|
ENTITY_ID_FORMAT, gw_dev.gw_id, hass=gw_dev.hass
|
||||||
)
|
)
|
||||||
self.friendly_name = gw_dev.name
|
self.friendly_name = gw_dev.name
|
||||||
|
self._attr_name = self.friendly_name
|
||||||
self.floor_temp = options.get(CONF_FLOOR_TEMP, DEFAULT_FLOOR_TEMP)
|
self.floor_temp = options.get(CONF_FLOOR_TEMP, DEFAULT_FLOOR_TEMP)
|
||||||
self.temp_read_precision = options.get(CONF_READ_PRECISION)
|
self.temp_read_precision = options.get(CONF_READ_PRECISION)
|
||||||
self.temp_set_precision = options.get(CONF_SET_PRECISION)
|
self.temp_set_precision = options.get(CONF_SET_PRECISION)
|
||||||
self.temporary_ovrd_mode = options.get(CONF_TEMPORARY_OVRD_MODE, True)
|
self.temporary_ovrd_mode = options.get(CONF_TEMPORARY_OVRD_MODE, True)
|
||||||
self._available = False
|
|
||||||
self._current_operation: HVACAction | None = None
|
|
||||||
self._current_temperature = None
|
|
||||||
self._hvac_mode = HVACMode.HEAT
|
|
||||||
self._new_target_temperature = None
|
|
||||||
self._target_temperature = None
|
|
||||||
self._away_mode_a = None
|
|
||||||
self._away_mode_b = None
|
|
||||||
self._away_state_a = False
|
|
||||||
self._away_state_b = False
|
|
||||||
self._unsub_options = None
|
self._unsub_options = None
|
||||||
self._unsub_updates = None
|
self._unsub_updates = None
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, gw_dev.gw_id)},
|
||||||
|
manufacturer="Schelte Bron",
|
||||||
|
model="OpenTherm Gateway",
|
||||||
|
name=gw_dev.name,
|
||||||
|
sw_version=gw_dev.gw_version,
|
||||||
|
)
|
||||||
|
self._attr_unique_id = gw_dev.gw_id
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def update_options(self, entry):
|
def update_options(self, entry):
|
||||||
@ -123,7 +136,7 @@ class OpenThermClimate(ClimateEntity):
|
|||||||
@callback
|
@callback
|
||||||
def receive_report(self, status):
|
def receive_report(self, status):
|
||||||
"""Receive and handle a new report from the Gateway."""
|
"""Receive and handle a new report from the Gateway."""
|
||||||
self._available = status != gw_vars.DEFAULT_STATUS
|
self._attr_available = status != gw_vars.DEFAULT_STATUS
|
||||||
ch_active = status[gw_vars.BOILER].get(gw_vars.DATA_SLAVE_CH_ACTIVE)
|
ch_active = status[gw_vars.BOILER].get(gw_vars.DATA_SLAVE_CH_ACTIVE)
|
||||||
flame_on = status[gw_vars.BOILER].get(gw_vars.DATA_SLAVE_FLAME_ON)
|
flame_on = status[gw_vars.BOILER].get(gw_vars.DATA_SLAVE_FLAME_ON)
|
||||||
cooling_active = status[gw_vars.BOILER].get(gw_vars.DATA_SLAVE_COOLING_ACTIVE)
|
cooling_active = status[gw_vars.BOILER].get(gw_vars.DATA_SLAVE_COOLING_ACTIVE)
|
||||||
@ -171,32 +184,6 @@ class OpenThermClimate(ClimateEntity):
|
|||||||
)
|
)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self):
|
|
||||||
"""Return availability of the sensor."""
|
|
||||||
return self._available
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the friendly name."""
|
|
||||||
return self.friendly_name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return device info."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._gateway.gw_id)},
|
|
||||||
manufacturer="Schelte Bron",
|
|
||||||
model="OpenTherm Gateway",
|
|
||||||
name=self._gateway.name,
|
|
||||||
sw_version=self._gateway.gw_version,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique ID."""
|
|
||||||
return self._gateway.gw_id
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def precision(self):
|
def precision(self):
|
||||||
"""Return the precision of the system."""
|
"""Return the precision of the system."""
|
||||||
@ -216,11 +203,6 @@ class OpenThermClimate(ClimateEntity):
|
|||||||
"""Return current HVAC mode."""
|
"""Return current HVAC mode."""
|
||||||
return self._hvac_mode
|
return self._hvac_mode
|
||||||
|
|
||||||
@property
|
|
||||||
def hvac_modes(self) -> list[HVACMode]:
|
|
||||||
"""Return available HVAC modes."""
|
|
||||||
return []
|
|
||||||
|
|
||||||
def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
def set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||||
"""Set the HVAC mode."""
|
"""Set the HVAC mode."""
|
||||||
_LOGGER.warning("Changing HVAC mode is not supported")
|
_LOGGER.warning("Changing HVAC mode is not supported")
|
||||||
@ -259,11 +241,6 @@ class OpenThermClimate(ClimateEntity):
|
|||||||
return PRESET_AWAY
|
return PRESET_AWAY
|
||||||
return PRESET_NONE
|
return PRESET_NONE
|
||||||
|
|
||||||
@property
|
|
||||||
def preset_modes(self):
|
|
||||||
"""Available preset modes to set."""
|
|
||||||
return []
|
|
||||||
|
|
||||||
def set_preset_mode(self, preset_mode: str) -> None:
|
def set_preset_mode(self, preset_mode: str) -> None:
|
||||||
"""Set the preset mode."""
|
"""Set the preset mode."""
|
||||||
_LOGGER.warning("Changing preset mode is not supported")
|
_LOGGER.warning("Changing preset mode is not supported")
|
||||||
@ -278,13 +255,3 @@ class OpenThermClimate(ClimateEntity):
|
|||||||
temp, self.temporary_ovrd_mode
|
temp, self.temporary_ovrd_mode
|
||||||
)
|
)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def min_temp(self):
|
|
||||||
"""Return the minimum temperature."""
|
|
||||||
return 1
|
|
||||||
|
|
||||||
@property
|
|
||||||
def max_temp(self):
|
|
||||||
"""Return the maximum temperature."""
|
|
||||||
return 30
|
|
||||||
|
@ -49,6 +49,7 @@ class OpenThermSensor(SensorEntity):
|
|||||||
"""Representation of an OpenTherm Gateway sensor."""
|
"""Representation of an OpenTherm Gateway sensor."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
_attr_entity_registry_enabled_default = False
|
||||||
|
|
||||||
def __init__(self, gw_dev, var, source, device_class, unit, friendly_name_format):
|
def __init__(self, gw_dev, var, source, device_class, unit, friendly_name_format):
|
||||||
"""Initialize the OpenTherm Gateway sensor."""
|
"""Initialize the OpenTherm Gateway sensor."""
|
||||||
@ -58,37 +59,39 @@ class OpenThermSensor(SensorEntity):
|
|||||||
self._gateway = gw_dev
|
self._gateway = gw_dev
|
||||||
self._var = var
|
self._var = var
|
||||||
self._source = source
|
self._source = source
|
||||||
self._value = None
|
self._attr_device_class = device_class
|
||||||
self._device_class = device_class
|
self._attr_native_unit_of_measurement = unit
|
||||||
self._unit = unit
|
|
||||||
if TRANSLATE_SOURCE[source] is not None:
|
if TRANSLATE_SOURCE[source] is not None:
|
||||||
friendly_name_format = (
|
friendly_name_format = (
|
||||||
f"{friendly_name_format} ({TRANSLATE_SOURCE[source]})"
|
f"{friendly_name_format} ({TRANSLATE_SOURCE[source]})"
|
||||||
)
|
)
|
||||||
self._friendly_name = friendly_name_format.format(gw_dev.name)
|
self._attr_name = friendly_name_format.format(gw_dev.name)
|
||||||
self._unsub_updates = None
|
self._unsub_updates = None
|
||||||
|
self._attr_unique_id = f"{gw_dev.gw_id}-{source}-{var}"
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, gw_dev.gw_id)},
|
||||||
|
manufacturer="Schelte Bron",
|
||||||
|
model="OpenTherm Gateway",
|
||||||
|
name=gw_dev.name,
|
||||||
|
sw_version=gw_dev.gw_version,
|
||||||
|
)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to updates from the component."""
|
"""Subscribe to updates from the component."""
|
||||||
_LOGGER.debug("Added OpenTherm Gateway sensor %s", self._friendly_name)
|
_LOGGER.debug("Added OpenTherm Gateway sensor %s", self._attr_name)
|
||||||
self._unsub_updates = async_dispatcher_connect(
|
self._unsub_updates = async_dispatcher_connect(
|
||||||
self.hass, self._gateway.update_signal, self.receive_report
|
self.hass, self._gateway.update_signal, self.receive_report
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_will_remove_from_hass(self) -> None:
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
"""Unsubscribe from updates from the component."""
|
"""Unsubscribe from updates from the component."""
|
||||||
_LOGGER.debug("Removing OpenTherm Gateway sensor %s", self._friendly_name)
|
_LOGGER.debug("Removing OpenTherm Gateway sensor %s", self._attr_name)
|
||||||
self._unsub_updates()
|
self._unsub_updates()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Return availability of the sensor."""
|
"""Return availability of the sensor."""
|
||||||
return self._value is not None
|
return self._attr_native_value is not None
|
||||||
|
|
||||||
@property
|
|
||||||
def entity_registry_enabled_default(self):
|
|
||||||
"""Disable sensors by default."""
|
|
||||||
return False
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def receive_report(self, status):
|
def receive_report(self, status):
|
||||||
@ -96,41 +99,5 @@ class OpenThermSensor(SensorEntity):
|
|||||||
value = status[self._source].get(self._var)
|
value = status[self._source].get(self._var)
|
||||||
if isinstance(value, float):
|
if isinstance(value, float):
|
||||||
value = f"{value:2.1f}"
|
value = f"{value:2.1f}"
|
||||||
self._value = value
|
self._attr_native_value = value
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the friendly name of the sensor."""
|
|
||||||
return self._friendly_name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self) -> DeviceInfo:
|
|
||||||
"""Return device info."""
|
|
||||||
return DeviceInfo(
|
|
||||||
identifiers={(DOMAIN, self._gateway.gw_id)},
|
|
||||||
manufacturer="Schelte Bron",
|
|
||||||
model="OpenTherm Gateway",
|
|
||||||
name=self._gateway.name,
|
|
||||||
sw_version=self._gateway.gw_version,
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique ID."""
|
|
||||||
return f"{self._gateway.gw_id}-{self._source}-{self._var}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the device class."""
|
|
||||||
return self._device_class
|
|
||||||
|
|
||||||
@property
|
|
||||||
def native_value(self):
|
|
||||||
"""Return the state of the device."""
|
|
||||||
return self._value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def native_unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return self._unit
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user