Skip to content

Commit

Permalink
Issue #93: Use THEN to execute (Action class).
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed Oct 16, 2018
1 parent cd189a5 commit 547f34f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions amazon_dash/action.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


class Action:
def __init__(self, use, params=None, condition=None, template=None):
self.use = use
self.params = params
self.condition = condition
self.template = template
4 changes: 3 additions & 1 deletion amazon_dash/device.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from amazon_dash.action import Action
from amazon_dash.confirmations import get_confirmation
from amazon_dash.exceptions import InvalidConfig
from amazon_dash.execute import ExecuteCmd, ExecuteUrl, ExecuteHomeAssistant, ExecuteOpenHab, ExecuteIFTTT, logger
Expand All @@ -23,12 +24,13 @@ def __init__(self, src, name, actions, config=None):
:param data: device data
"""
config = config or {}
actions = actions or []

if isinstance(src, Device):
src = src.src
self.src = src.lower()
self.name = name or self.src
self.actions = actions
self.actions = [Action(**action) for action in actions]
self.config = config

def execute(self, root_allowed=False):
Expand Down
4 changes: 2 additions & 2 deletions amazon_dash/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ def test_device(device, file, root_allowed=False):
"""
config = Config(file)
config.read()
if not device in config['devices']:
if not device in config.devices:
raise InvalidDevice('Device {} is not in config file.'.format(device))
logger.info(Device(device, config['devices'][device], config).execute(root_allowed))
logger.info(config.devices[device].execute(root_allowed))

0 comments on commit 547f34f

Please sign in to comment.