Skip to content

Commit

Permalink
1.3.0 (#5)
Browse files Browse the repository at this point in the history
* Add Fan device class and support variables

* Add device type string for Z-Wave Watts

* Bump version to 1.3.0
  • Loading branch information
marthoc authored Mar 5, 2021
1 parent 0b39aed commit 2c686b7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions libhomeseer/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DEVICE_ZWAVE_SWITCH_BINARY = "Z-Wave Switch Binary"
DEVICE_ZWAVE_SWITCH_MULTILEVEL = "Z-Wave Switch Multilevel"
DEVICE_ZWAVE_TEMPERATURE = "Z-Wave Temperature"
DEVICE_ZWAVE_WATTS = "Z-Wave Watts"

RELATIONSHIP_ROOT = 2
RELATIONSHIP_STANDALONE = 3
Expand Down
31 changes: 31 additions & 0 deletions libhomeseer/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CONTROL_USE_DIM = 3
CONTROL_USE_LOCK = 18
CONTROL_USE_UNLOCK = 19
CONTROL_USE_FAN = 23
CONTROL_LABEL_LOCK = "Lock"
CONTROL_LABEL_UNLOCK = "Unlock"

Expand All @@ -19,6 +20,7 @@
SUPPORT_LOCK = 4
SUPPORT_UNLOCK = 8
SUPPORT_DIM = 16
SUPPORT_FAN = 32

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -196,6 +198,26 @@ async def dim(self, percent: int) -> None:
await self._request("get", params=params)


class HomeSeerFanDevice(HomeSeerSwitchableDevice):
"""Representation of a HomeSeer device that has a Fan or DimFan control pair."""

@property
def speed_percent(self) -> float:
"""Returns a number from 0 to 1 representing the current speed percentage."""
return self.value / self._on_value

async def speed(self, percent: int) -> None:
"""Set the speed of the device on a scale from 0 to 100."""
if percent < 0 or percent > 100:
raise ValueError("Percent must be an integer from 0 to 100")

value = int(self._on_value * (percent / 100))

params = {"request": "controldevicebyvalue", "ref": self.ref, "value": value}

await self._request("get", params=params)


class HomeSeerLockableDevice(HomeSeerStatusDevice):
"""Representation of a HomeSeer device that has Lock and Unlock control pairs."""

Expand Down Expand Up @@ -237,6 +259,7 @@ def get_device(
) -> Optional[
Union[
HomeSeerDimmableDevice,
HomeSeerFanDevice,
HomeSeerLockableDevice,
HomeSeerStatusDevice,
HomeSeerSwitchableDevice,
Expand All @@ -247,6 +270,7 @@ def get_device(
based on the control pairs detected for the device.
On/Off = HomeSeerSwitchableDevice
On/Off/Dim = HomeSeerDimmableDevice
On/Off/Fan = HomeSeerFanDevice
Lock/Unlock = HomeSeerLockableDevice
other = HomeSeerStatusDevice
"""
Expand Down Expand Up @@ -282,6 +306,8 @@ def get_device(
supported_features |= SUPPORT_UNLOCK
elif control_use == CONTROL_USE_DIM:
supported_features |= SUPPORT_DIM
elif control_use == CONTROL_USE_FAN:
supported_features |= SUPPORT_FAN
break

if supported_features == SUPPORT_ON | SUPPORT_OFF:
Expand All @@ -294,6 +320,11 @@ def get_device(
raw_data, request, on_value=on_value, off_value=off_value
)

elif supported_features == SUPPORT_ON | SUPPORT_OFF | SUPPORT_FAN:
return HomeSeerFanDevice(
raw_data, request, on_value=on_value, off_value=off_value
)

elif supported_features == SUPPORT_LOCK | SUPPORT_UNLOCK:
return HomeSeerLockableDevice(
raw_data, request, lock_value=lock_value, unlock_value=unlock_value
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setuptools.setup(
name="libhomeseer",
version="1.2.2",
version="1.3.0",
author="Mark Coombes",
author_email="[email protected]",
description="Python3 async library for interacting with HomeSeer HS3 and HS4 via JSON and ASCII",
Expand Down

0 comments on commit 2c686b7

Please sign in to comment.