tweaks
This commit is contained in:
@@ -18,6 +18,10 @@ class CriticalAlert(Hass):
|
|||||||
def msg(self) -> str:
|
def msg(self) -> str:
|
||||||
return self.args['msg']
|
return self.args['msg']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device(self) -> str:
|
||||||
|
return self.args['device']
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def critical_sensor(self) -> Entity:
|
def critical_sensor(self) -> Entity:
|
||||||
return self.get_entity(self.args['sensor'])
|
return self.get_entity(self.args['sensor'])
|
||||||
@@ -29,21 +33,16 @@ class CriticalAlert(Hass):
|
|||||||
message=self.msg,
|
message=self.msg,
|
||||||
tag=self.name,
|
tag=self.name,
|
||||||
)
|
)
|
||||||
n.critical = True
|
|
||||||
n.color = 'red'
|
n.color = 'red'
|
||||||
n.icon = 'fire-alert'
|
n.icon = 'fire-alert'
|
||||||
n.add_action('clear', 'Clear Alert')
|
n.add_action('clear', 'Clear Alert')
|
||||||
return n
|
return n
|
||||||
|
|
||||||
async def alert(self,
|
def alert(self, entity: str, attribute: str, old: str, new: str, **kwargs):
|
||||||
entity: str,
|
|
||||||
attribute: str,
|
|
||||||
old: str, new: str,
|
|
||||||
**kwargs):
|
|
||||||
self.alert_active = new == 'on'
|
self.alert_active = new == 'on'
|
||||||
|
|
||||||
if self.alert_active:
|
if self.alert_active:
|
||||||
self.alert_handle = await self.run_every(
|
self.alert_handle = self.run_every(
|
||||||
self.repeat_alert,
|
self.repeat_alert,
|
||||||
start='now', interval=2.0
|
start='now', interval=2.0
|
||||||
)
|
)
|
||||||
@@ -55,13 +54,14 @@ class CriticalAlert(Hass):
|
|||||||
def repeat_alert(self, **kwargs):
|
def repeat_alert(self, **kwargs):
|
||||||
if self.alert_active:
|
if self.alert_active:
|
||||||
self.android_tts(
|
self.android_tts(
|
||||||
self.args['device'],
|
device=self.device,
|
||||||
tts_text=self.msg,
|
tts_text=self.msg,
|
||||||
critical=True
|
critical=True
|
||||||
)
|
)
|
||||||
self.call_service(**self.critical_notification.to_service_call())
|
self.call_service(**self.critical_notification.to_service_call())
|
||||||
|
|
||||||
def clear_alert(self, event_name: str = None, data: dict = None, **cb_args: dict):
|
def clear_alert(self, event_name: str = None, data: dict = None, **cb_args: dict):
|
||||||
|
self.log(event_name, level='DEBUG')
|
||||||
if self.alert_active:
|
if self.alert_active:
|
||||||
self.alert_active = False
|
self.alert_active = False
|
||||||
self.cancel_timer(self.alert_handle)
|
self.cancel_timer(self.alert_handle)
|
||||||
|
|||||||
Reference in New Issue
Block a user