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

Commit

Permalink
Merge pull request #19 from andrewsayre/dev
Browse files Browse the repository at this point in the history
v0.7.0
  • Loading branch information
andrewsayre authored Dec 30, 2019
2 parents 20bc61d + 631c4a4 commit 1b4b744
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 34 deletions.
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"python.pythonPath": ".venv\\Scripts\\python.exe",
"python.pythonPath": "/Users/andrewsayre/repos/pysmartthings/.venv/bin/python3",
"[python]": {
"editor.rulers": [79]
"editor.rulers": [
79
]
}
}
10 changes: 8 additions & 2 deletions pysmartthings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
Capability)
from .const import __title__, __version__ # noqa
from .device import (
Command, Device, DeviceEntity, DeviceStatus, DeviceStatusBase, DeviceType)
DEVICE_TYPE_DTH, DEVICE_TYPE_ENDPOINT_APP, DEVICE_TYPE_OCF,
DEVICE_TYPE_UNKNOWN, DEVICE_TYPE_VIPER, Command, Device, DeviceEntity,
DeviceStatus, DeviceStatusBase)
from .errors import APIErrorDetail, APIInvalidGrant, APIResponseError
from .installedapp import (
InstalledApp, InstalledAppEntity, InstalledAppStatus, InstalledAppType)
Expand Down Expand Up @@ -40,12 +42,16 @@
'Attribute',
'Capability',
# device
'DEVICE_TYPE_DTH',
'DEVICE_TYPE_ENDPOINT_APP',
'DEVICE_TYPE_OCF',
'DEVICE_TYPE_UNKNOWN',
'DEVICE_TYPE_VIPER',
'Command',
'Device',
'DeviceEntity',
'DeviceStatus',
'DeviceStatusBase',
'DeviceType',
# error
'APIErrorDetail',
'APIInvalidGrant',
Expand Down
2 changes: 1 addition & 1 deletion pysmartthings/capability.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
'waterSensor': ['water'],
'windowShade': ['windowShade']
}
CAPABILITIES = [c for c in CAPABILITIES_TO_ATTRIBUTES]
CAPABILITIES = list(CAPABILITIES_TO_ATTRIBUTES)
ATTRIBUTES = {attrib
for attributes in CAPABILITIES_TO_ATTRIBUTES.values()
for attrib in attributes}
Expand Down
2 changes: 1 addition & 1 deletion pysmartthings/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Define consts for the pysmartthings package."""

__title__ = "pysmartthings"
__version__ = "0.6.9"
__version__ = "0.7.0"
24 changes: 10 additions & 14 deletions pysmartthings/device.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
"""Defines a SmartThings device."""
from collections import defaultdict, namedtuple
import colorsys
from enum import Enum
import re
from typing import Any, Dict, Mapping, Optional, Sequence, Tuple

from .api import Api
from .capability import ATTRIBUTE_ON_VALUES, Attribute, Capability
from .entity import Entity

DEVICE_TYPE_OCF = 'OCF'
DEVICE_TYPE_DTH = 'DTH'
DEVICE_TYPE_UNKNOWN = 'UNKNOWN'
DEVICE_TYPE_ENDPOINT_APP = 'ENDPOINT_APP'
DEVICE_TYPE_VIPER = 'VIPER'

COLOR_HEX_MATCHER = re.compile('^#[A-Fa-f0-9]{6}$')
Status = namedtuple('status', 'value unit data')
STATUS_NONE = Status(None, None, None)
Expand Down Expand Up @@ -58,15 +63,6 @@ class Command:
unlock = 'unlock'


class DeviceType(Enum):
"""Define the device type."""

UNKNOWN = 'UNKNOWN'
DTH = 'DTH'
ENDPOINT_APP = 'ENDPOINT_APP'
VIPER = 'VIPER'


class Device:
"""Represents a SmartThings device."""

Expand All @@ -77,7 +73,7 @@ def __init__(self):
self._label = None
self._location_id = None
self._room_id = None
self._type = DeviceType.UNKNOWN
self._type = DEVICE_TYPE_UNKNOWN
self._device_type_id = None
self._device_type_name = None
self._device_type_network = None
Expand All @@ -91,7 +87,7 @@ def apply_data(self, data: dict):
self._label = data['label']
self._location_id = data['locationId']
self._room_id = data.get('roomId')
self._type = DeviceType(data['type'])
self._type = data['type']
self._components.clear()
self._capabilities.clear()
for component in data['components']:
Expand All @@ -101,7 +97,7 @@ def apply_data(self, data: dict):
self._capabilities.extend(capabilities)
else:
self._components[component_id] = capabilities
if self._type is DeviceType.DTH:
if self._type == DEVICE_TYPE_DTH:
dth = data['dth']
self._device_type_id = dth["deviceTypeId"]
self._device_type_name = dth["deviceTypeName"]
Expand Down Expand Up @@ -140,7 +136,7 @@ def room_id(self):
return self._room_id

@property
def type(self) -> DeviceType:
def type(self) -> str:
"""Get the SmartThings device type."""
return self._type

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aiohttp==3.5.4
aiohttp==3.6.2
16 changes: 8 additions & 8 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
coveralls==1.7.0
flake8==3.7.7
flake8-docstrings==1.3.0
pydocstyle==3.0.0
pylint==2.3.1
pytest==4.4.1
coveralls==1.9.2
flake8==3.7.9
flake8-docstrings==1.5.0
pydocstyle==5.0.1
pylint==2.4.4
pytest==5.3.2
pytest-asyncio==0.10.0
pytest-cov==2.7.1
pytest-cov==2.8.1
pytest-timeout==1.3.3
yarl==1.3.0
yarl==1.4.2
7 changes: 4 additions & 3 deletions tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from pysmartthings.capability import Attribute, Capability
from pysmartthings.device import (
Device, DeviceEntity, DeviceStatus, DeviceType, Status)
DEVICE_TYPE_DTH, DEVICE_TYPE_UNKNOWN, Device, DeviceEntity, DeviceStatus,
Status)

from .conftest import DEVICE_ID, LOCATION_ID, ROOM_ID
from .utilities import get_json
Expand All @@ -19,7 +20,7 @@ def test_init():
# Arrange/Act
device = Device()
# Assert
assert device.type == DeviceType.UNKNOWN
assert device.type == DEVICE_TYPE_UNKNOWN
assert device.capabilities == []
assert device.components == {}

Expand All @@ -37,7 +38,7 @@ def test_apply_data():
assert device.label == 'Front Porch Lights'
assert device.location_id == LOCATION_ID
assert device.room_id == ROOM_ID
assert device.type is DeviceType.DTH
assert device.type == DEVICE_TYPE_DTH
assert device.device_type_id == '8a9d4b1e3b9b1fe3013b9b206a7f000d'
assert device.device_type_name == 'Dimmer Switch'
assert device.device_type_network == 'ZWAVE'
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ setenv =
deps =
-r{toxinidir}/test-requirements.txt
commands =
pytest tests --timeout=30 --duration=10 {posargs}
pytest tests --timeout=30 {posargs}

[testenv:lint]
setenv =
Expand All @@ -29,4 +29,4 @@ setenv =
deps =
-r{toxinidir}/test-requirements.txt
commands =
pytest tests --timeout=30 --duration=10 --cov {posargs}
pytest tests --timeout=30 --cov {posargs}

0 comments on commit 1b4b744

Please sign in to comment.