Skip to content

Commit

Permalink
refactor key
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-dcs committed Dec 24, 2024
1 parent 5d6a842 commit bb1b247
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 419 deletions.
15 changes: 10 additions & 5 deletions custom_components/ithodaalderop/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def async_setup_entry(
sensors = []
if config_entry.data[CONF_ADDON_TYPE] == "cve":
for description in CVE_BINARY_SENSORS:
description.key = f"{MQTT_BASETOPIC["cve"]}/{MQTT_STATETOPIC["cve"]}"
description.topic = f"{MQTT_BASETOPIC["cve"]}/{MQTT_STATETOPIC["cve"]}"
sensors.append(IthoBinarySensor(description, config_entry))

if config_entry.data[CONF_ADDON_TYPE] == "noncve" and config_entry.data[
Expand All @@ -57,12 +57,14 @@ async def async_setup_entry(
hru_sensors = HRU_ECO_350_BINARY_SENSORS

for description in hru_sensors:
description.key = f"{MQTT_BASETOPIC["noncve"]}/{MQTT_STATETOPIC["noncve"]}"
description.topic = (
f"{MQTT_BASETOPIC["noncve"]}/{MQTT_STATETOPIC["noncve"]}"
)
sensors.append(IthoBinarySensor(description, config_entry))

if config_entry.data[CONF_ADDON_TYPE] == "wpu":
for description in WPU_BINARY_SENSORS:
description.key = f"{MQTT_BASETOPIC["wpu"]}/{MQTT_STATETOPIC["wpu"]}"
description.topic = f"{MQTT_BASETOPIC["wpu"]}/{MQTT_STATETOPIC["wpu"]}"
sensors.append(IthoBinarySensor(description, config_entry))

async_add_entities(sensors)
Expand All @@ -81,6 +83,7 @@ def __init__(
) -> None:
"""Initialize the binary sensor."""
self.entity_description = description
self.entity_description.translation_key = self.entity_description.key

model = ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]
if config_entry.data[CONF_ADDON_TYPE] == "noncve":
Expand All @@ -93,7 +96,9 @@ def __init__(
name="Itho Daalderop " + ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]],
)

self._attr_unique_id = f"itho_{ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]}_{description.translation_key}"
self._attr_unique_id = (
f"itho_{ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]}_{description.key}"
)
self.entity_id = f"binary_sensor.{self._attr_unique_id}"

@property
Expand Down Expand Up @@ -127,5 +132,5 @@ def message_received(message):
self.async_write_ha_state()

await mqtt.async_subscribe(
self.hass, self.entity_description.key, message_received, 1
self.hass, self.entity_description.topic, message_received, 1
)
66 changes: 33 additions & 33 deletions custom_components/ithodaalderop/definitions/autotemp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Definitions for Itho sensors added to MQTT."""
"""Definitions for Itho Autotemp sensors added to MQTT."""

from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import (
Expand All @@ -13,7 +13,7 @@

AUTOTEMP_COMM_SPACE_SENSOR_TEMPLATE = IthoSensorEntityDescription(
json_field="Comm space X (sec)",
translation_key="comm_space",
key="comm_space",
unique_id_template="comm_space_x",
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
Expand All @@ -23,7 +23,7 @@

AUTOTEMP_DISTRIBUTOR_VALVE_SENSOR_TEMPLATE = IthoSensorEntityDescription(
json_field="Distributor X valve Y",
translation_key="distributor_valve",
key="distributor_valve",
unique_id_template="distributor_x_valve_y",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
Expand All @@ -32,7 +32,7 @@
AUTOTEMP_MALFUNCTION_VALVE_DECTECTION_DIST_SENSOR_TEMPLATE = (
IthoSensorEntityDescription(
json_field="Malfunction valve detection dist X",
translation_key="malfunction_valve_detection_dist",
key="malfunction_valve_detection_dist",
unique_id_template="malfunction_valve_detection_dist_x",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
Expand All @@ -42,28 +42,28 @@
AUTOTEMP_ROOM_SENSORS: tuple[IthoSensorEntityDescription, ...] = (
IthoSensorEntityDescription(
json_field="Room X power % (%)",
translation_key="power_perc",
key="power_perc",
device_class=SensorDeviceClass.POWER_FACTOR,
native_unit_of_measurement="%",
state_class=SensorStateClass.MEASUREMENT,
),
IthoSensorEntityDescription(
json_field="Room X power kW (kW)",
translation_key="power_kw",
key="power_kw",
device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=UnitOfPower.KILO_WATT,
state_class=SensorStateClass.MEASUREMENT,
),
IthoSensorEntityDescription(
json_field="Room X setp",
translation_key="setpoint_temp",
key="setpoint_temp",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
),
IthoSensorEntityDescription(
json_field="Room X temp",
translation_key="actual_temp",
key="actual_temp",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
Expand All @@ -73,149 +73,149 @@
AUTOTEMP_SENSORS: tuple[IthoSensorEntityDescription, ...] = (
IthoSensorEntityDescription(
json_field="Condition",
translation_key="condition",
key="condition",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Condition cool",
translation_key="condition_cool",
key="condition_cool",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Condition off",
translation_key="condition_off",
key="condition_off",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Cycle counter (sec)",
translation_key="cycle_counter",
key="cycle_counter",
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Desired power (%)",
translation_key="desired_power",
key="desired_power",
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Error",
translation_key="error",
key="error",
entity_category=EntityCategory.DIAGNOSTIC,
),
IthoSensorEntityDescription(
json_field="Heat source",
translation_key="heat_source",
key="heat_source",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="LED_Fast",
translation_key="led_fast",
key="led_fast",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="LED_On",
translation_key="led_on",
key="led_on",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="LED_Slow",
translation_key="led_slow",
key="led_slow",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Mode",
translation_key="mode",
key="mode",
),
IthoSensorEntityDescription(
json_field="Outdoor temp (°C)",
translation_key="outdoor_temp",
key="outdoor_temp",
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
),
IthoSensorEntityDescription(
json_field="Particulars",
translation_key="particulars",
key="particulars",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Rest cycle time (sec)",
translation_key="rest_cycle_time",
key="rest_cycle_time",
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Rest vent time (sec)",
translation_key="rest_vent_time",
key="rest_vent_time",
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Rest vent time (sec)",
translation_key="rest_vent_time",
key="rest_vent_time",
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="State cool",
translation_key="state_cool",
key="state_cool",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="State hand",
translation_key="state_hand",
key="state_hand",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="state hand",
translation_key="state_hand2",
key="state_hand2",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="State heating",
translation_key="state_heating",
key="state_heating",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="State off",
translation_key="state",
key="state",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Time active zone too cold (sec)",
translation_key="time_active_zone_too_cold",
key="time_active_zone_too_cold",
native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Valve failure detection distributor 1",
translation_key="valve_failure_detection_distributor_1",
key="valve_failure_detection_distributor_1",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
Expand All @@ -224,14 +224,14 @@
AUTOTEMP_VALVE_SENSOR_TEMPLATE: tuple[IthoSensorEntityDescription, ...] = (
IthoSensorEntityDescription(
json_field="VX_valve",
translation_key="v_valve",
key="v_valve",
unique_id_template="vx_valve",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
),
IthoSensorEntityDescription(
json_field="Valve failure distributor X",
translation_key="valve_failure_distributor",
key="valve_failure_distributor",
unique_id_template="valve_failure_distributor_x",
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
Expand Down
6 changes: 4 additions & 2 deletions custom_components/ithodaalderop/definitions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
class IthoBinarySensorEntityDescription(BinarySensorEntityDescription):
"""Binary Sensor entity description for Itho."""

key: str | None = None
state: Callable | None = None
json_field: str | None = None
key: str | None = None
topic: str | None = None
icon: str | None = None
icon_off: str | None = None
icon_on: str | None = None
Expand All @@ -34,9 +35,10 @@ class IthoBinarySensorEntityDescription(BinarySensorEntityDescription):
class IthoSensorEntityDescription(SensorEntityDescription):
"""Sensor entity description for Itho."""

key: str | None = None
state: Callable | None = None
json_field: str | None = None
key: str | None = None
topic: str | None = None
icon: str | None = None
unique_id_template: str | None = None
unique_id: str | None = None
Expand Down
4 changes: 2 additions & 2 deletions custom_components/ithodaalderop/definitions/co2_remote.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Definitions for Itho sensors added to MQTT."""
"""Definitions for Itho CO2 Remote sensors added to MQTT."""

from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.const import CONCENTRATION_PARTS_PER_MILLION

from .base import IthoSensorEntityDescription

REMOTE_SENSOR_TEMPLATE = IthoSensorEntityDescription(
translation_key="remote",
key="remote",
device_class=SensorDeviceClass.CO2,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
state_class=SensorStateClass.MEASUREMENT,
Expand Down
Loading

0 comments on commit bb1b247

Please sign in to comment.