updating configuration

This commit is contained in:
Your Name
2019-11-17 09:59:10 +03:00
parent cf8737292d
commit 3b5104a10d
22 changed files with 201 additions and 94 deletions
+19 -9
View File
@@ -20,17 +20,31 @@ import appdaemon.plugins.hass.hassapi as hass
class WaterLeak(hass.Hass):
ringtone = 2
gw_mac = ''
sensors = []
def initialize(self):
if 'sensor' not in self.args or 'valve' not in self.args or 'notify' not in self.args:
self.error("Please provide sensor, valve and notify in config!")
return
self.listen_state(self.water_leak, self.args['sensor'])
self.sensors = self.get_water_leak_sensors()
self.log("leak sensors: {}".format(self.sensors))
for sensor in self.sensors:
self.listen_state(self.water_leak, sensor)
def get_water_leak_sensors(self):
sensors = []
devices = self.get_state()
for sensor in devices:
if not sensor.startswith(self.args['sensor_prefix']):
continue
sensors.append(sensor)
return sensors
def water_leak(self, entity, attribute, old, new, kwargs):
if new == "on":
self.send_alarm()
def send_alarm(self):
self.log('water leak alarm triggered!')
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
return
@@ -44,10 +58,6 @@ class WaterLeak(hass.Hass):
self.notify(message, name = self.args['notify'])
message = "Состояние датчиков протечки:\n"
attributes = self.get_state(self.args['sensor'], attribute = "all")
if 'attributes' in attributes:
attributes = attributes['attributes']
if 'entity_id' in attributes:
for entity_id in attributes["entity_id"]:
message += '{} ({}) = {}\n'.format(self.friendly_name(entity_id), entity_id, self.get_state(entity_id))
self.notify(message, name = self.args['notify'])
for entity_id in self.sensors:
message += '{} ({}) = {}\n'.format(self.friendly_name(entity_id), entity_id, self.get_state(entity_id))
self.notify(message, name = self.args['notify'])