Skip to content

Commit

Permalink
Merge pull request #71 from jasperslits/translations_nl
Browse files Browse the repository at this point in the history
Fix NL translations and code in sensor for reading MQTT callback
  • Loading branch information
jasperslits authored Nov 23, 2024
2 parents 91d7bae + 4e59cf4 commit 01120ee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
50 changes: 29 additions & 21 deletions custom_components/ithodaalderop/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def _create_autotemprooms(config_entry: ConfigEntry):
if room not in ("", "Room " + str(x)):
for sensor in template_sensors:
sensor.json_field = sensor.json_field.replace("X", str(x))
sensor.key = f"{MQTT_BASETOPIC["autotemp"]}/{MQTT_STATETOPIC["autotemp"]}"
sensor.key = (
f"{MQTT_BASETOPIC["autotemp"]}/{MQTT_STATETOPIC["autotemp"]}"
)
sensor.affix = room
room_sensors.append(sensor)

Expand Down Expand Up @@ -121,11 +123,15 @@ async def async_setup_entry(

if config_entry.data[CONF_ADDON_TYPE] == "autotemp":
for description in list(AUTOTEMPSENSORS):
description.key = f"{MQTT_BASETOPIC["autotemp"]}/{MQTT_STATETOPIC["autotemp"]}"
description.key = (
f"{MQTT_BASETOPIC["autotemp"]}/{MQTT_STATETOPIC["autotemp"]}"
)
sensors.append(IthoSensorAutotemp(description, config_entry))

for description in _create_autotemprooms(config_entry):
description.key = f"{MQTT_BASETOPIC["autotemp"]}/{MQTT_STATETOPIC["autotemp"]}"
description.key = (
f"{MQTT_BASETOPIC["autotemp"]}/{MQTT_STATETOPIC["autotemp"]}"
)
sensors.append(IthoSensorAutotempRoom(description, config_entry))

async_add_entities(sensors)
Expand Down Expand Up @@ -163,7 +169,6 @@ def __init__(
self._attr_unique_id = f"itho_{ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]}_{description.translation_key}"
self.entity_id = f"sensor.{self._attr_unique_id}"


@property
def icon(self) -> str | None:
"""Pick the right icon."""
Expand Down Expand Up @@ -235,22 +240,27 @@ class IthoSensorAutotempRoom(IthoBaseSensor):
"""Representation of Itho add-on room sensor for Autotemp data that is updated via MQTT."""

def __init__(
self,
description: IthoSensorEntityDescription,
config_entry: ConfigEntry
self, description: IthoSensorEntityDescription, config_entry: ConfigEntry
) -> None:
"""Construct sensor for Autotemp."""
unique_id = f"itho_{ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]}_{description.translation_key}_{description.affix.lower()}"

self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, f"{config_entry.data[CONF_ADDON_TYPE]}_room_{description.affix.lower()}")},
identifiers={
(
DOMAIN,
f"{config_entry.data[CONF_ADDON_TYPE]}_room_{description.affix.lower()}",
)
},
manufacturer=MANUFACTURER,
model=f"{ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]} Spider",
name=f"Spider {description.affix.capitalize()}",
via_device=(DOMAIN, config_entry.data[CONF_ADDON_TYPE]),
)

super().__init__(description, config_entry, unique_id, use_base_sensor_device=False)
super().__init__(
description, config_entry, unique_id, use_base_sensor_device=False
)

async def async_added_to_hass(self) -> None:
"""Subscribe to MQTT events."""
Expand All @@ -259,7 +269,7 @@ async def async_added_to_hass(self) -> None:
def message_received(message):
"""Handle new MQTT messages."""
payload = json.loads(message.payload)
value = payload[self.entity_description.json_field, None]
value = payload.get(self.entity_description.json_field, None)

self._attr_native_value = value
self.async_write_ha_state()
Expand All @@ -273,9 +283,7 @@ class IthoSensorCO2Remote(IthoBaseSensor):
"""Representation of Itho add-on sensor for a Remote that is updated via MQTT."""

def __init__(
self,
description: IthoSensorEntityDescription,
config_entry: ConfigEntry
self, description: IthoSensorEntityDescription, config_entry: ConfigEntry
) -> None:
"""Construct sensor for Remote."""
unique_id = f"itho_{ADDON_TYPES[config_entry.data[CONF_ADDON_TYPE]]}_{description.translation_key}_{description.affix.lower()}"
Expand All @@ -301,6 +309,7 @@ def message_received(message):
self.hass, self.entity_description.key, message_received, 1
)


class IthoSensorFan(IthoBaseSensor):
"""Representation of a Itho add-on sensor that is updated via MQTT."""

Expand Down Expand Up @@ -380,7 +389,9 @@ def message_received(message):
if json_field == "Highest received RH value (%RH)":
_error_description = ""
if isinstance(value, (int, float)) and float(value) > 100:
_error_description = NONCVE_RH_ERROR_CODE.get(int(value), "Unknown error")
_error_description = NONCVE_RH_ERROR_CODE.get(
int(value), "Unknown error"
)
value = None

self._extra_state_attributes = {
Expand All @@ -394,21 +405,19 @@ def message_received(message):
self.hass, self.entity_description.key, message_received, 1
)


class IthoSensorLastCommand(IthoBaseSensor):
"""Representation of Itho add-on sensor for Last Command that is updated via MQTT."""

def __init__(
self,
description: IthoSensorEntityDescription,
config_entry: ConfigEntry
self, description: IthoSensorEntityDescription, config_entry: ConfigEntry
) -> None:
"""Construct sensor for WPU."""
super().__init__(description, config_entry)

async def async_added_to_hass(self) -> None:
"""Subscribe to MQTT events."""


@callback
def message_received(message):
"""Handle new MQTT messages."""
Expand All @@ -422,13 +431,12 @@ def message_received(message):
self.hass, self.entity_description.key, message_received, 1
)


class IthoSensorWPU(IthoBaseSensor):
"""Representation of Itho add-on sensor for WPU that is updated via MQTT."""

def __init__(
self,
description: IthoSensorEntityDescription,
config_entry: ConfigEntry
self, description: IthoSensorEntityDescription, config_entry: ConfigEntry
) -> None:
"""Construct sensor for WPU."""
super().__init__(description, config_entry)
Expand Down
14 changes: 7 additions & 7 deletions custom_components/ithodaalderop/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
"name": "Battery Leeg"
},
"error": {
"name": "Error"
"name": "Fout"
},
"fan_setpoint_rpm": {
"name": "Fan Stand"
"name": "Ventilator Stand"
},
"fan_speed": {
"name": "Fan Snelheid"
"name": "Ventilator Snelheid"
},
"flow_sensor": {
"name": "Stroomsnelheid"
Expand Down Expand Up @@ -93,7 +93,7 @@
"power_kw": {
"name": "Vermogen (kW)"
},
"power_perc%": {
"power_perc": {
"name": "Vermogen (%)"
},
"remaining_override_timer": {
Expand All @@ -109,10 +109,10 @@
"name": "Kamertemperatuur"
},
"setpoint_temp": {
"name": "Temperatuur Instelling"
"name": "Ingestelde temperatuur"
},
"state": {
"name": "Staat"
"name": "Status"
},
"status": {
"name": "Status"
Expand All @@ -127,7 +127,7 @@
"name": "Temperatuur naar bron"
},
"thermostat": {
"name": "Thermostat"
"name": "Thermostaat boiler"
},
"total_operation_time": {
"name": "Totale bedrijfstijd"
Expand Down

0 comments on commit 01120ee

Please sign in to comment.