Skip to content

Commit

Permalink
Merge pull request #27 from marcgeurts/feature/add-legionella-check
Browse files Browse the repository at this point in the history
Add legionella check and locales
  • Loading branch information
markvader authored Aug 3, 2023
2 parents 092158e + f6963e2 commit 6951f03
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 23 deletions.
16 changes: 16 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/sonic_hacs.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions custom_components/sonic/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def property_radio_disconnection(self) -> bool:
"""Return True if the radio disconnection notification is enabled at property."""
return self._property_notification_settings["radio_disconnection"]

@property
def property_legionella_check(self) -> bool:
"""Return True if the legionella check notification is enabled at property."""
return self._property_notification_settings["legionella_risk"]

@property
def property_low_water_temperature_check(self) -> bool:
"""Return True if the low water temperature notification is enabled at property."""
return self._property_notification_settings["low_water_temperature"]

async def _update_property(self, *_) -> None:
"""Update the property information from the API."""
Expand Down
151 changes: 132 additions & 19 deletions custom_components/sonic/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
from .property import PropertyDataUpdateCoordinator
from .entity import SonicEntity, PropertyEntity


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Sonic switches from config entry."""
devices: list[SonicDeviceDataUpdateCoordinator] = hass.data[SONIC_DOMAIN][
Expand All @@ -42,6 +43,8 @@ async def async_setup_entry(
PressureTestFailedAlert(property),
PressureTestSkippedAlert(property),
RadioDisconnectionAlert(property),
LegionellaCheckAlert(property),
LowWaterTemperatureAlert(property),
]
)

Expand Down Expand Up @@ -159,13 +162,15 @@ def icon(self):

async def async_turn_on(self, **kwargs) -> None:
"""Turn on the Pressure Tests Enabled Function"""
await self._device.api_client.property.async_update_property_settings(self._device.id, {'pressure_tests_enabled': True})
await self._device.api_client.property.async_update_property_settings(self._device.id,
{'pressure_tests_enabled': True})
self._state = True
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn off the Pressure Tests Enabled Function"""
await self._device.api_client.property.async_update_property_settings(self._device.id, {'pressure_tests_enabled': False})
await self._device.api_client.property.async_update_property_settings(self._device.id,
{'pressure_tests_enabled': False})
self._state = False
self.async_write_ha_state()

Expand Down Expand Up @@ -204,13 +209,15 @@ def icon(self):

async def async_turn_on(self, **kwargs) -> None:
"""Turn on the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'cloud_disconnection': True})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'cloud_disconnection': True})
self._state = True
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn off the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'cloud_disconnection': False})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'cloud_disconnection': False})
self._state = False
self.async_write_ha_state()

Expand Down Expand Up @@ -249,13 +256,15 @@ def icon(self):

async def async_turn_on(self, **kwargs) -> None:
"""Turn on the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'low_battery_level': True})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'low_battery_level': True})
self._state = True
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn off the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'low_battery_level': False})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'low_battery_level': False})
self._state = False
self.async_write_ha_state()

Expand All @@ -270,6 +279,100 @@ async def async_added_to_hass(self):
self.async_on_remove(self._device.async_add_listener(self.async_update_state))


class LegionellaCheckAlert(PropertyEntity, SwitchEntity):
"""Switch class for the Property Legionella Check Alert."""

_attr_entity_category = EntityCategory.CONFIG

def __init__(self, device: PropertyDataUpdateCoordinator) -> None:
"""Initialize the Property legionella_check Alert switch."""
super().__init__("legionella_check_alert", "Alerts - Legionella Check", device)
self._state = self._device.property_legionella_check == True

@property
def is_on(self) -> bool:
"""Return True if the Alert is enabled."""
return self._state

@property
def icon(self):
"""Return the icon to use for the switch."""
if self.is_on:
return "mdi:bell"
return "mdi:bell-off"

async def async_turn_on(self, **kwargs) -> None:
"""Turn on the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'legionella_risk': True})
self._state = True
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn off the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'legionella_risk': False})
self._state = False
self.async_write_ha_state()

@callback
def async_update_state(self) -> None:
"""Retrieve the latest switch state and update the state machine."""
self._state = self._device.property_legionella_check == True
self.async_write_ha_state()

async def async_added_to_hass(self):
"""When entity is added to hass."""
self.async_on_remove(self._device.async_add_listener(self.async_update_state))


class LowWaterTemperatureAlert(PropertyEntity, SwitchEntity):
"""Switch class for the Property Low Water Temperature Alert."""

_attr_entity_category = EntityCategory.CONFIG

def __init__(self, device: PropertyDataUpdateCoordinator) -> None:
"""Initialize the Property Low Water Temperature Alert switch."""
super().__init__("low_water_temperature_alert", "Alerts - Low Water Temperature", device)
self._state = self._device.property_low_water_temperature_check == True

@property
def is_on(self) -> bool:
"""Return True if the Alert is enabled."""
return self._state

@property
def icon(self):
"""Return the icon to use for the switch."""
if self.is_on:
return "mdi:bell"
return "mdi:bell-off"

async def async_turn_on(self, **kwargs) -> None:
"""Turn on the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'low_water_temperature': True})
self._state = True
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn off the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'low_water_temperature': False})
self._state = False
self.async_write_ha_state()

@callback
def async_update_state(self) -> None:
"""Retrieve the latest switch state and update the state machine."""
self._state = self._device.property_low_water_temperature_check == True
self.async_write_ha_state()

async def async_added_to_hass(self):
"""When entity is added to hass."""
self.async_on_remove(self._device.async_add_listener(self.async_update_state))


class DeviceHandleMovedAlert(PropertyEntity, SwitchEntity):
"""Switch class for the Device Handle Moved Alert."""

Expand All @@ -294,13 +397,15 @@ def icon(self):

async def async_turn_on(self, **kwargs) -> None:
"""Turn on the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'device_handle_moved': True})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'device_handle_moved': True})
self._state = True
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn off the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'device_handle_moved': False})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'device_handle_moved': False})
self._state = False
self.async_write_ha_state()

Expand Down Expand Up @@ -339,13 +444,15 @@ def icon(self):

async def async_turn_on(self, **kwargs) -> None:
"""Turn on the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'health_check_failed': True})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'health_check_failed': True})
self._state = True
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn off the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'health_check_failed': False})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'health_check_failed': False})
self._state = False
self.async_write_ha_state()

Expand Down Expand Up @@ -384,13 +491,15 @@ def icon(self):

async def async_turn_on(self, **kwargs) -> None:
"""Turn on the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'pressure_test_failed': True})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'pressure_test_failed': True})
self._state = True
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn off the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'pressure_test_failed': False})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'pressure_test_failed': False})
self._state = False
self.async_write_ha_state()

Expand Down Expand Up @@ -429,13 +538,15 @@ def icon(self):

async def async_turn_on(self, **kwargs) -> None:
"""Turn on the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'pressure_test_skipped': True})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'pressure_test_skipped': True})
self._state = True
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn off the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'pressure_test_skipped': False})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'pressure_test_skipped': False})
self._state = False
self.async_write_ha_state()

Expand Down Expand Up @@ -474,13 +585,15 @@ def icon(self):

async def async_turn_on(self, **kwargs) -> None:
"""Turn on the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'radio_disconnection': True})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'radio_disconnection': True})
self._state = True
self.async_write_ha_state()

async def async_turn_off(self, **kwargs) -> None:
"""Turn off the Alert"""
await self._device.api_client.property.async_update_property_notifications(self._device.id, {'radio_disconnection': False})
await self._device.api_client.property.async_update_property_notifications(self._device.id,
{'radio_disconnection': False})
self._state = False
self.async_write_ha_state()

Expand Down
24 changes: 24 additions & 0 deletions custom_components/sonic/translations/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"config": {
"abort": {
"already_configured": "Gerät ist bereits konfiguriert"
},
"error": {
"cannot_connect": "Verbindung nicht möglich",
"invalid_auth": "Ungültige Authentifizierung",
"unknown": "Unerwarteter Fehler"
},
"step": {
"user": {
"data": {
"password": "Passwort",
"username": "Nutzername"
},
"data_description": {
"username": "Hero Labs-Benutzername, normalerweise eine E-Mail-Adresse."
},
"description": "Melden Sie sich bei Ihrem Hero Labs-Konto an."
}
}
}
}
24 changes: 24 additions & 0 deletions custom_components/sonic/translations/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"config": {
"abort": {
"already_configured": "Apparaat is al geconfigureerd"
},
"error": {
"cannot_connect": "Kon niet verbinden",
"invalid_auth": "Ongeldige authenticatie",
"unknown": "Onverwachte fout"
},
"step": {
"user": {
"data": {
"password": "Wachtwoord",
"username": "Gebruikersnaam"
},
"data_description": {
"username": "Hero Labs gebruikersnaam, meestal een e-mailadres."
},
"description": "Log in op uw Hero Labs-account."
}
}
}
}

0 comments on commit 6951f03

Please sign in to comment.