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
+54 -55
View File
@@ -1,56 +1,55 @@
import datetime
from automation import Automation, Base # type: ignore
#
# App to send email report for low balance
#
# Args:
#
# threshold = value below which battery levels are reported and email is sent
# always_send = set to 1 to override threshold and force send
#
# None
#
# Release Notes
#
# Version 1.0:
# Initial Version
class Balance(Base):
def initialize(self):
super().initialize()
self.check_balance({"force": 1})
self.run_daily(self.check_balance, datetime.time(10, 0, 0))
def check_balance(self, kwargs):
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
return
values = {}
low = []
for key in self.entity_ids:
device = self.entity_ids[key]
balance = self.get_state(device)
if balance != None and self.is_number(balance):
if float(balance) < self.args["threshold"]:
low.append(device)
values[device] = balance
message=""
if low:
message += "Пожалуйста пополните баланс: (< {}) \n".format(self.args["threshold"])
for device in low:
message += " - {}: {}\n".format(self.friendly_name(device), values[device])
message += "\n\n"
if low or ("always_send" in self.args and self.args["always_send"] == 1) or ("force" in kwargs and kwargs["force"] == 1):
if message != "":
self.notify(message, name = "telegram") #name = "telegram_monster"
def is_number(self, s):
try:
float(s)
return True
except ValueError:
import datetime
from automation import Automation, Base # type: ignore
#
# App to send email report for low balance
#
# Args:
#
# threshold = value below which battery levels are reported and email is sent
# always_send = set to 1 to override threshold and force send
#
# None
#
# Release Notes
#
# Version 1.0:
# Initial Version
class Balance(Base):
def initialize(self):
super().initialize()
self.check_balance({"force": 1})
self.run_daily(self.check_balance, datetime.time(10, 0, 0))
def check_balance(self, kwargs):
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
return
values = {}
low = []
for key in self.entity_ids:
device = self.entity_ids[key]
balance = self.get_state(device)
if balance != None and self.is_number(balance):
if float(balance) < self.args["threshold"]:
low.append(device)
values[device] = balance
message=""
if low:
message += "Пожалуйста пополните баланс: (< {}) \n".format(self.args["threshold"])
for device in low:
message += " - {}: {}\n".format(self.friendly_name(device), values[device])
message += "\n\n"
if low or ("always_send" in self.args and self.args["always_send"] == 1) or ("force" in kwargs and kwargs["force"] == 1):
if message != "":
self.notify(message, name = "telegram") #name = "telegram_monster"
def is_number(self, s):
try:
float(s)
return True
except ValueError:
return False
@@ -26,22 +26,22 @@ class WaterCountersAlarm(hass.Hass):
self.send_threasold = self.args['send_threasold']
self.check_send_dates({"force": 1})
time = datetime.time(10, 0, 0)
self.run_daily(self.check_checkup_dates, time)
self.run_daily(self.check_send_dates, time)
# self.check_send_dates([])
self.run_daily(self.check_checkup_dates, datetime.time(10, 0, 0))
self.run_daily(self.check_send_dates, datetime.time(10, 1, 0))
#self.check_checkup_dates([])
def check_send_dates(self, kwargs):
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
return
devices = self.get_state()
if devices == None:
return
values = {}
send_devices = []
for deviceName in devices:
device = devices[deviceName]
if (device == None):
continue
send_date = None
if "attributes" in device:
if "date" in device["attributes"]:
@@ -75,20 +75,27 @@ class WaterCountersAlarm(hass.Hass):
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
return
devices = self.get_state()
entities = self.get_state()
if entities == None:
return
values = {}
checkup_devices = []
for device in devices:
for entity_id in entities:
entity = entities[entity_id]
if entity == None:
# self.log('not found {} in entities list.'.format(entity_id))
continue
checkup = None
if "attributes" in devices[device]:
if "checkup" in devices[device]["attributes"]:
checkup = devices[device]["attributes"]["checkup"]
if "attributes" in entity:
if "checkup" in entity["attributes"]:
checkup = entity["attributes"]["checkup"]
if checkup != None:
self.log('found device {} with checkup date {}'.format(device, checkup))
self.log('found device {} with checkup date {}'.format(entity_id, checkup))
checkup_date = datetime.datetime.strptime(checkup, '%Y-%m-%d')
if (checkup_date - datetime.timedelta(days=self.checkup_threasold)) < datetime.datetime.now():
checkup_devices.append(device)
values[device] = checkup
checkup_devices.append(entity_id)
values[entity_id] = checkup
message=""
if checkup_devices: