Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.

Commit e0f91cf

Browse files
committed
Added event timer support and updated README in anticipation of publish.
1 parent e03eee4 commit e0f91cf

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# pysmartapp
2-
A python implementation of the WebHook-based SmartThings SmartApp (work in process). Please see the [SmartApp documentation](https://smartthings.developer.samsung.com/develop/guides/smartapps/basics.html) for more information.
3-
42
[![Build Status](https://travis-ci.org/andrewsayre/pysmartapp.svg?branch=master)](https://travis-ci.org/andrewsayre/pysmartapp)
53
[![Coverage Status](https://coveralls.io/repos/github/andrewsayre/pysmartapp/badge.svg?branch=master)](https://coveralls.io/github/andrewsayre/pysmartapp?branch=master)
6-
[![image](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
4+
[![image](https://img.shields.io/pypi/v/pysmartapp.svg)](https://pypi.org/project/pysmartapp/)
5+
[![image](https://img.shields.io/pypi/pyversions/pysmartapp.svg)](https://pypi.org/project/pysmartapp/)
6+
[![image](https://img.shields.io/pypi/l/pysmartapp.svg)](https://pypi.org/project/pysmartapp/)
7+
[![image](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
8+
9+
A python implementation of the WebHook-based [SmartThings SmartApp](https://smartthings.developer.samsung.com/develop/guides/smartapps/basics.html).

pysmartapp/consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
LIFECYCLE_OAUTH_CALLBACK = 'OAUTH_CALLBACK'
1111
LIFECYCLE_UNINSTALL = 'UNINSTALL'
1212
EVENT_TYPE_DEVICE = 'DEVICE_EVENT'
13+
EVENT_TYPE_TIMER = 'TIMER_EVENT'

pysmartapp/event.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Sequence
44

5-
from .consts import EVENT_TYPE_DEVICE
5+
from .consts import EVENT_TYPE_DEVICE, EVENT_TYPE_TIMER
66
from .request import EmptyDataResponse, Request, Response
77

88

@@ -32,6 +32,17 @@ def __init__(self, data: dict):
3232
self._attribute = device_event['attribute']
3333
self._value = device_event['value']
3434
self._state_change = device_event['stateChange']
35+
self._timer_name = None
36+
self._timer_type = None
37+
self._timer_time = None
38+
self._timer_expression = None
39+
if self._event_type == EVENT_TYPE_TIMER:
40+
timer_event = data['timerEvent']
41+
self._event_id = timer_event['eventId']
42+
self._timer_name = timer_event['name']
43+
self._timer_type = timer_event['type']
44+
self._timer_time = timer_event['time']
45+
self._timer_expression = timer_event['expression']
3546

3647
@property
3748
def event_type(self) -> str:
@@ -83,6 +94,26 @@ def state_change(self) -> bool:
8394
"""Get whether this is a new state change."""
8495
return self._state_change
8596

97+
@property
98+
def timer_name(self) -> str:
99+
"""Get the name of the timer schedule."""
100+
return self._timer_name
101+
102+
@property
103+
def timer_type(self) -> str:
104+
"""Get the type of time."""
105+
return self._timer_type
106+
107+
@property
108+
def timer_time(self) -> str:
109+
"""Get the time the timer fired."""
110+
return self._timer_time
111+
112+
@property
113+
def timer_expression(self) -> str:
114+
"""Get the timer firing expression."""
115+
return self._timer_expression
116+
86117

87118
class EventRequest(Request):
88119
"""Define the EventRequest class."""

tests/fixtures/event_request.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
"value" :"active",
2525
"stateChange": true
2626
}
27+
},
28+
{
29+
"eventType": "TIMER_EVENT",
30+
"timerEvent": {
31+
"eventId": "string",
32+
"name": "lights_off_timeout",
33+
"type": "CRON",
34+
"time": "2017-09-13T04:18:12.469Z",
35+
"expression": "string"
36+
}
2737
}
2838
]
2939
},

tests/test_event.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
""""Tests for the event module."""
22

3-
from pysmartapp.consts import EVENT_TYPE_DEVICE, LIFECYCLE_EVENT
3+
from pysmartapp.consts import (EVENT_TYPE_DEVICE, EVENT_TYPE_TIMER,
4+
LIFECYCLE_EVENT)
45
from pysmartapp.event import Event, EventRequest
56

67
from .utilities import get_fixture
@@ -27,14 +28,14 @@ def test_init():
2728
assert req.installed_app_config == {}
2829
assert req.settings == data['settings']
2930
assert req.auth_token == 'f01894ce-013a-434a-b51e-f82126fd72e4'
30-
assert len(req.events) == 1
31+
assert len(req.events) == 2
3132

3233

3334
class TestEvent:
3435
"""Tests for the Event class."""
3536

3637
@staticmethod
37-
def test_init():
38+
def test_init_device_event():
3839
"""Tests the init method."""
3940
# Arrange
4041
data = get_fixture('event_request')['eventData']['events'][0]
@@ -51,3 +52,18 @@ def test_init():
5152
assert evt.attribute == 'motion'
5253
assert evt.value == 'active'
5354
assert evt.state_change
55+
56+
@staticmethod
57+
def test_init_timer_event():
58+
"""Tests the init method."""
59+
# Arrange
60+
data = get_fixture('event_request')['eventData']['events'][1]
61+
# Act
62+
evt = Event(data)
63+
# Assert
64+
assert evt.event_type == EVENT_TYPE_TIMER
65+
assert evt.event_id == 'string'
66+
assert evt.timer_name == 'lights_off_timeout'
67+
assert evt.timer_type == 'CRON'
68+
assert evt.timer_time == '2017-09-13T04:18:12.469Z'
69+
assert evt.timer_expression == 'string'

0 commit comments

Comments
 (0)