Skip to content

Commit

Permalink
use new adutils lib
Browse files Browse the repository at this point in the history
  • Loading branch information
benleb committed Sep 29, 2019
1 parent 7a4b325 commit 2ab954d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 16 additions & 16 deletions apps/notifreeze/notifreeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "❄️ "
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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",
)

Expand All @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
adutils>=0.2.5
adutils~=0.4.0

0 comments on commit 2ab954d

Please sign in to comment.