Skip to content

Commit

Permalink
Update schemas (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt authored Mar 12, 2024
1 parent 0389550 commit eff93f3
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 23 deletions.
23 changes: 18 additions & 5 deletions aiohue/v2/models/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,10 @@ class GradientFeature(GradientFeatureBase):
class Signal(Enum):
"""Enum with various signals."""

NO_SIGNAL = "no_signal"
ON_OFF = "on_off"
ON_OFF_COLOR = "on_off_color"
ALTERNATING = "alternating"
NO_SIGNAL = "no_signal" # No signal is active. Write “no_signal” to stop active signal.
ON_OFF = "on_off" # Toggles between max brightness and Off in fixed color.
ON_OFF_COLOR = "on_off_color" # Toggles between off and max brightness with color provided.
ALTERNATING = "alternating" # Alternates between 2 provided colors.
UNKNOWN = "unknown"

@classmethod
Expand All @@ -528,10 +528,23 @@ class SignalingFeatureStatus:
class SignalingFeature:
"""Feature containing signaling properties."""

status: SignalingFeatureStatus = field(default=SignalingFeatureStatus)
# status: Indicates status of active signal. Not available when inactive.
status: SignalingFeatureStatus | None = None
# signal_values: Signals that the light supports.
signal_values: list[Signal] = field(default_factory=list)


@dataclass
class SignalingFeaturePut:
"""Represent SignalingFeature object when sent to the Hue API."""

signal: Signal
# Duration has a max of 65534000 ms and a stepsize of 1 second.
# Values in between steps will be rounded. Duration is ignored for no_signal.
duration: int | None = None
colors: list[ColorFeaturePut] | None = None


class PowerUpPreset(Enum):
"""Enum with available powerup presets."""

Expand Down
13 changes: 11 additions & 2 deletions aiohue/v2/models/grouped_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
DimmingFeatureBase,
DynamicsFeaturePut,
OnFeature,
SignalingFeature,
SignalingFeaturePut,
)
from .resource import ResourceTypes
from .resource import ResourceIdentifier, ResourceTypes


@dataclass
Expand All @@ -29,10 +31,16 @@ class GroupedLight:
"""

id: str
owner: ResourceIdentifier
id_v1: str | None = None
# on: Joined on control & aggregated on state.
# “on” is true if any light in the group is on.
on: OnFeature | None = None
# dimming: Joined dimming control.
# “dimming.brightness” contains average brightness of group containing turned-on lights only.
dimming: DimmingFeatureBase | None = None
alert: AlertFeature | None = None
alert: AlertFeature | None = None # Joined alert control
signaling: SignalingFeature | None = None
type: ResourceTypes = ResourceTypes.GROUPED_LIGHT


Expand All @@ -52,3 +60,4 @@ class GroupedLightPut:
color: ColorFeaturePut | None = None
dynamics: DynamicsFeaturePut | None = None
alert: AlertFeaturePut | None = None
signaling: SignalingFeaturePut | None = None
2 changes: 2 additions & 0 deletions aiohue/v2/models/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
PowerUpFeature,
PowerUpFeaturePut,
SignalingFeature,
SignalingFeaturePut,
TimedEffectsFeature,
TimedEffectsFeaturePut,
)
Expand Down Expand Up @@ -148,3 +149,4 @@ class LightPut:
effects: EffectsFeaturePut | None = None
timed_effects: TimedEffectsFeaturePut | None = None
powerup: PowerUpFeaturePut | None = None
signaling: SignalingFeaturePut | None = None
1 change: 1 addition & 0 deletions aiohue/v2/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ResourceTypes(Enum):
CONTACT = "contact"
TAMPER = "tamper"
CAMERA_MOTION = "camera_motion"
PRIVATE_GROUP = "private_group"
UNKNOWN = "unknown"

@classmethod
Expand Down
82 changes: 66 additions & 16 deletions tests/fixtures/v2_resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
{
"id": "9c489c26-9e34-4fcd-8324-a57e3a664cc0",
"status": "unpaired",
"status_values": ["pairing", "paired", "unpaired"],
"status_values": [
"pairing",
"paired",
"unpaired"
],
"type": "homekit"
},
{
Expand Down Expand Up @@ -581,7 +585,9 @@
},
{
"alert": {
"action_values": ["breathe"]
"action_values": [
"breathe"
]
},
"color": {
"gamut": {
Expand Down Expand Up @@ -620,7 +626,10 @@
"speed": 0.627,
"speed_valid": true,
"status": "dynamic_palette",
"status_values": ["none", "dynamic_palette"]
"status_values": [
"none",
"dynamic_palette"
]
},
"id": "02cba059-9c2c-4d45-97e4-4f79b1bfbaa1",
"id_v1": "/lights/29",
Expand All @@ -640,7 +649,9 @@
},
{
"alert": {
"action_values": ["breathe"]
"action_values": [
"breathe"
]
},
"color_temperature": {
"mirek": 369,
Expand All @@ -658,7 +669,9 @@
"speed": 0.0,
"speed_valid": false,
"status": "none",
"status_values": ["none"]
"status_values": [
"none"
]
},
"id": "3a6710fa-4474-4eba-b533-5e6e72968feb",
"id_v1": "/lights/4",
Expand All @@ -678,7 +691,9 @@
},
{
"alert": {
"action_values": ["breathe"]
"action_values": [
"breathe"
]
},
"color": {
"gamut": {
Expand Down Expand Up @@ -717,7 +732,10 @@
"speed": 0.627,
"speed_valid": true,
"status": "dynamic_palette",
"status_values": ["none", "dynamic_palette"]
"status_values": [
"none",
"dynamic_palette"
]
},
"id": "b3fe71ef-d0ef-48de-9355-d9e604377df0",
"id_v1": "/lights/16",
Expand All @@ -737,13 +755,17 @@
},
{
"alert": {
"action_values": ["breathe"]
"action_values": [
"breathe"
]
},
"dynamics": {
"speed": 0.0,
"speed_valid": false,
"status": "none",
"status_values": ["none"]
"status_values": [
"none"
]
},
"id": "7697ac8a-25aa-4576-bb40-0036c0db15b9",
"id_v1": "/lights/23",
Expand All @@ -763,7 +785,9 @@
},
{
"alert": {
"action_values": ["breathe"]
"action_values": [
"breathe"
]
},
"color": {
"gamut": {
Expand Down Expand Up @@ -794,7 +818,10 @@
"speed": 0.6389,
"speed_valid": true,
"status": "dynamic_palette",
"status_values": ["none", "dynamic_palette"]
"status_values": [
"none",
"dynamic_palette"
]
},
"id": "74a45fee-1b3d-4553-b5ab-040da8a10cfd",
"id_v1": "/lights/11",
Expand All @@ -814,7 +841,9 @@
},
{
"alert": {
"action_values": ["breathe"]
"action_values": [
"breathe"
]
},
"color": {
"gamut": {
Expand Down Expand Up @@ -853,7 +882,10 @@
"speed": 0.627,
"speed_valid": true,
"status": "dynamic_palette",
"status_values": ["none", "dynamic_palette"]
"status_values": [
"none",
"dynamic_palette"
]
},
"gradient": {
"points": [
Expand Down Expand Up @@ -1361,35 +1393,53 @@
},
{
"alert": {
"action_values": ["breathe"]
"action_values": [
"breathe"
]
},
"id": "f2416154-9607-43ab-a684-4453108a200e",
"id_v1": "/groups/5",
"on": {
"on": true
},
"owner": {
"rid": "a3fbc86a-bf4c-4c69-899d-d6eafc37e288",
"rtype": "bridge_home"
},
"type": "grouped_light"
},
{
"alert": {
"action_values": ["breathe"]
"action_values": [
"breathe"
]
},
"id": "0a74457c-cb8d-44c2-a5a5-dcb7b3675550",
"id_v1": "/groups/0",
"on": {
"on": true
},
"owner": {
"rid": "a3fbc86a-bf4c-4c69-899d-d6eafc37e288",
"rtype": "bridge_home"
},
"type": "grouped_light"
},
{
"alert": {
"action_values": ["breathe"]
"action_values": [
"breathe"
]
},
"id": "e937f8db-2f0e-49a0-936e-027e60e15b34",
"id_v1": "/groups/3",
"on": {
"on": false
},
"owner": {
"rid": "a3fbc86a-bf4c-4c69-899d-d6eafc37e288",
"rtype": "bridge_home"
},
"type": "grouped_light"
},
{
Expand Down

0 comments on commit eff93f3

Please sign in to comment.