From 35457d6afae766b6b922cba9ff75bc78c02659c6 Mon Sep 17 00:00:00 2001 From: Daniel Mason Date: Tue, 22 Sep 2020 19:25:19 +0800 Subject: [PATCH 1/2] feat: add missing params and Context --- custom_components/mqtt_code/processor.py | 9 ++++----- custom_components/processor/__init__.py | 3 ++- custom_components/processor/yaml_scheduler.py | 13 ++++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/custom_components/mqtt_code/processor.py b/custom_components/mqtt_code/processor.py index c38cbd6..cbdfd42 100644 --- a/custom_components/mqtt_code/processor.py +++ b/custom_components/mqtt_code/processor.py @@ -293,7 +293,7 @@ def process(self, payload): # for k in j.keys(): # self.log.debug("%s %s" % (k, j[k])) value = j["value"] - self.log.debug("Is %s a match for %s?" % (value, self.name)) + # self.log.debug("Is %s a match for %s?" % (value, self.name)) for p in self.payloads_on: if int(p) == value: self.log.info("Processing %s on code" % (p)) @@ -311,10 +311,9 @@ def process(self, payload): def message_received(self, message): """Handle new MQTT messages.""" - self.log.debug("Message received: " + str(message)) + # self.log.debug("Message received: " + str(message)) self.process(message.payload) - self.log.debug("after process") def update_state(self, payload, action): @@ -344,8 +343,8 @@ def update_state(self, payload, action): def handleRFCode(self, action): # self.hass.states.set(DOMAIN + '.last_triggered_by', self.name) # hass.states.set('rf_processor.last_triggered_time', time.localtime(time.time())) - self.log.debug("event: " + str(self.event)) - self.log.debug("globalEvent: " + str(self.globalEvent)) + # self.log.debug("event: " + str(self.event)) + # self.log.debug("globalEvent: " + str(self.globalEvent)) self.device.handle_event(self) if self.event or self.globalEvent: self.log.debug("Sending event.") diff --git a/custom_components/processor/__init__.py b/custom_components/processor/__init__.py index ec9b1d4..48a1138 100644 --- a/custom_components/processor/__init__.py +++ b/custom_components/processor/__init__.py @@ -7,6 +7,7 @@ import logging from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity import Entity +# from homeassistant.compoennts.alert import Alert _LOGGER = logging.getLogger(__name__) VERSION = '2.0.1' @@ -105,4 +106,4 @@ def state_attributes(self): return None - \ No newline at end of file + diff --git a/custom_components/processor/yaml_scheduler.py b/custom_components/processor/yaml_scheduler.py index 96b6023..8ff303f 100644 --- a/custom_components/processor/yaml_scheduler.py +++ b/custom_components/processor/yaml_scheduler.py @@ -1,6 +1,8 @@ import logging; from datetime import datetime, timedelta, date, time import homeassistant.helpers.script as script +from homeassistant.core import Context +from . import DOMAIN _LOGGER = logging.getLogger(__name__) from homeassistant.util import dt VERSION='2.0.2' @@ -40,7 +42,7 @@ def __init__(self, mapping, name, args): # super(Action,self).__init__(self.hass,'processor-action' + name,name,args) self.log = logging.getLogger("{}.actions.{}".format(mapping.log.name, name)) self.log.info("Creating action " + name) - if 'name' is None: + if name is None: self.log.error("Missing name in Action") self.schedule_name = name self.log.debug("Script Sequence: " + str(args)) @@ -71,9 +73,14 @@ def execute(self, schedule): ## passed in call-back function if self.schedule_name == schedule: self.log.debug("Executing actions in Action {}".format(self.schedule_name)) try: - script.Script.call_from_config(self.mapping.device.hass, self._script_config) - except Exception as e: + # self.log.error(str(dir(script))) + # self.log.error(str(dir(script.service))) + s = script.Script(self.mapping.device.hass, self._script_config, self.schedule_name, DOMAIN) + context = Context(parent_id="device.%s" % (self.mapping.device.name), id="actions.{}".format( self.schedule_name)) + s.run(context=context) + except Exception as e: self.log.error("Error calling supplied script: " + str(e)) + raise e From 3ecb182ab26e5e170e11c31e1e5c7c676d0d9d7d Mon Sep 17 00:00:00 2001 From: Daniel Mason Date: Tue, 22 Sep 2020 19:29:38 +0800 Subject: [PATCH 2/2] ci: bump version --- custom_components/mqtt_code/processor.py | 2 +- custom_components/processor/__init__.py | 2 +- custom_components/processor/yaml_scheduler.py | 2 +- hacs.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/mqtt_code/processor.py b/custom_components/mqtt_code/processor.py index cbdfd42..f6451ad 100644 --- a/custom_components/mqtt_code/processor.py +++ b/custom_components/mqtt_code/processor.py @@ -5,7 +5,7 @@ # E.g. RF codes, Bluetooth ids, etc. # Documentation: https://github.com/danobot/mqtt_payload_processor -# Version: v2.0.2 +# Version: v2.0.3 import homeassistant.loader as loader import logging diff --git a/custom_components/processor/__init__.py b/custom_components/processor/__init__.py index 48a1138..de9d1ce 100644 --- a/custom_components/processor/__init__.py +++ b/custom_components/processor/__init__.py @@ -9,7 +9,7 @@ from homeassistant.helpers.entity import Entity # from homeassistant.compoennts.alert import Alert _LOGGER = logging.getLogger(__name__) -VERSION = '2.0.1' +VERSION = '2.0.3' DEPENDENCIES = ['mqtt'] diff --git a/custom_components/processor/yaml_scheduler.py b/custom_components/processor/yaml_scheduler.py index 8ff303f..b4c6b94 100644 --- a/custom_components/processor/yaml_scheduler.py +++ b/custom_components/processor/yaml_scheduler.py @@ -5,7 +5,7 @@ from . import DOMAIN _LOGGER = logging.getLogger(__name__) from homeassistant.util import dt -VERSION='2.0.2' +VERSION='2.0.3' class Scheduler: def __init__(self, yaml): diff --git a/hacs.json b/hacs.json index 438c615..3388993 100644 --- a/hacs.json +++ b/hacs.json @@ -1,4 +1,4 @@ { "name": "Processor", - "homeassistant": "0.103.2" + "homeassistant": "0.115.1" }