Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new Hue Tap Dial (relative rotary) #146

Merged
merged 1 commit into from
Aug 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions aiohue/v2/controllers/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from aiohue.util import dataclass_to_dict

from ..models.button import Button, ButtonEvent
from ..models.relative_rotary import RelativeRotary
from ..models.device_power import DevicePower
from ..models.geofence_client import GeofenceClient
from ..models.light_level import LightLevel, LightLevelPut
Expand All @@ -24,6 +25,7 @@
GeofenceClient,
LightLevel,
Motion,
RelativeRotary,
Temperature,
ZigbeeConnectivity,
]
Expand Down Expand Up @@ -145,6 +147,14 @@ async def set_enabled(self, id: str, enabled: bool) -> None:
await self.update(id, MotionPut(enabled=enabled))


class RelativeRotaryController(BaseResourcesController[Type[Button]]):
"""Controller holding and managing HUE resources of type `relative_rotary`."""

item_type = ResourceTypes.RELATIVE_ROTARY
item_cls = RelativeRotary
allow_parser_error = True


class TemperatureController(BaseResourcesController[Type[Temperature]]):
"""Controller holding and managing HUE resources of type `temperature`."""

Expand All @@ -171,6 +181,7 @@ def __init__(self, bridge: "HueBridgeV2") -> None:
self.geofence_client = GeofenceClientController(bridge)
self.light_level = LightLevelController(bridge)
self.motion = MotionController(bridge)
self.relative_rotary = RelativeRotaryController(bridge)
self.temperature = TemperatureController(bridge)
self.zigbee_connectivity = ZigbeeConnectivityController(bridge)
super().__init__(
Expand All @@ -181,6 +192,7 @@ def __init__(self, bridge: "HueBridgeV2") -> None:
self.geofence_client,
self.light_level,
self.motion,
self.relative_rotary,
self.temperature,
self.zigbee_connectivity,
],
Expand Down
70 changes: 70 additions & 0 deletions aiohue/v2/models/relative_rotary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Model(s) for relative_rotary resource on HUE bridge.

https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_relative_rotary
"""
from dataclasses import dataclass
from enum import Enum
from typing import Optional, Type

from .resource import ResourceIdentifier, ResourceTypes


class RelativeRotaryAction(Enum):
"""Enum with possible relative_rotary actions."""

START = "start"
REPEAT = "repeat"
UNKNOWN = "unknown"

@classmethod
def _missing_(cls: Type, value: str):
"""Set default enum member if an unknown value is provided."""
return RelativeRotaryAction.UNKNOWN


class RelativeRotaryDirection(Enum):
"""Enum with possible rotary directions."""

CLOCK_WISE = "clock_wise"
COUNTER_CLOCK_WISE = "counter_clock_wise"


@dataclass
class RelativeRotaryRotation:
"""Represent Rotation object as used by the Hue api."""

direction: RelativeRotaryDirection
duration: int
steps: int


@dataclass
class RelativeRotaryEvent:
"""Represent RelativeRotaryEvent object as used by the Hue api."""

action: RelativeRotaryAction
rotation: RelativeRotaryRotation


@dataclass
class RelativeRotaryFeature:
"""Represent RelativeRotaryFeature object as used by the Hue api."""

last_event: RelativeRotaryEvent


@dataclass
class RelativeRotary:
"""
Represent a (full) `RelativeRotary` resource when retrieved from the api.

https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_relative_rotary_get
"""

id: str
owner: ResourceIdentifier

relative_rotary: Optional[RelativeRotaryFeature] = None
id_v1: Optional[str] = None
type: ResourceTypes = ResourceTypes.RELATIVE_ROTARY