diff --git a/apps/notifreeze/notifreeze.py b/apps/notifreeze/notifreeze.py index 23710a0..b3d0f91 100644 --- a/apps/notifreeze/notifreeze.py +++ b/apps/notifreeze/notifreeze.py @@ -13,7 +13,7 @@ from typing import Any, Dict, Sequence, Union import appdaemon.plugins.hass.hassapi as hass -import adutils +from adutils import ADutils APP_NAME = "NotiFreeze" APP_ICON = "❄️ " @@ -55,11 +55,12 @@ def initialize(self) -> None: self.sensors[entity] = f"sensor.temperature_{room}" self.listen_state(self.handler, entity=entity) - adutils.show_info( - self.log, APP_NAME, self.app_config, self.sensors, icon=APP_ICON, appdaemon_version=self.get_ad_version() - ) + self.adu = ADutils(APP_NAME, self.app_config, icon=APP_ICON, ad=self) + self.adu.show_info() - def handler(self, entity: str, attr: Any, old: str, new: str, kwargs: Dict[str, Any]) -> None: + def handler( + self, entity: str, attr: Any, old: str, new: str, kwargs: Dict[str, Any] + ) -> None: """Handle state changes.""" try: indoor, outdoor, difference = self.get_temperatures(entity) @@ -80,10 +81,10 @@ def handler(self, entity: str, attr: Any, old: str, new: str, kwargs: Dict[str, entity_id=entity, ) - self.log( - f"{APP_ICON} reminder: ({self.app_config['initial_delay']}min): " + self.adu.log( + f"reminder: ({self.app_config['initial_delay']}min): " f"{self.strip_sensor(entity)} | diff: {difference:.1f}°C", - ascii_encode=False, + icon={APP_ICON}, ) elif old == "on" and new == "off" and entity in self.handles: @@ -98,7 +99,9 @@ def notification(self, kwargs: Dict[str, Any]) -> None: try: indoor, outdoor, difference = self.get_temperatures(entity) except (ValueError, TypeError) as error: - self.log(f"No valid temperature values to calculate difference: {error}") + self.adu.log( + f"No valid temperature values to calculate difference: {error}" + ) return # check if all required conditions still met, then processing with notification @@ -144,10 +147,10 @@ def notification(self, kwargs: Dict[str, Any]) -> None: counter=counter + 1, ) - self.log( - f"{APP_ICON} notification sent to {self.app_config['notify_service']}: " + self.adu.log( + f"notification sent to {self.app_config['notify_service']}: " f"{message}", - ascii_encode=False, + icon={APP_ICON}, level="DEBUG", ) @@ -158,10 +161,7 @@ def notification(self, kwargs: Dict[str, Any]) -> None: def kill_timer(self, entity: str) -> None: """Cancel scheduled task/timers.""" self.cancel_timer(self.handles[entity]) - self.log( - f"{APP_ICON} reminder deleted: {self.strip_sensor(entity)}", - ascii_encode=False, - ) + self.adu.log(f"reminder deleted: {self.strip_sensor(entity)}", icon={APP_ICON}) def get_temperatures(self, entity: str) -> Sequence[float]: """Get temperature indoor, outdoor and the abs. difference of both.""" diff --git a/requirements.txt b/requirements.txt index 169e5a5..d7134ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -adutils>=0.2.5 +adutils~=0.4.0