Skip to content

Commit

Permalink
messages: Add new Button messages
Browse files Browse the repository at this point in the history
  • Loading branch information
delfick committed Jul 27, 2022
1 parent e9d4ef3 commit 125e54e
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1 deletion.
19 changes: 19 additions & 0 deletions modules/photons_messages/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ class Direction(Enum):
FORWARD = 1


class ButtonGesture(Enum):
PRESS = 1
HOLD = 2
PRESS_PRESS = 3
PRESS_HOLD = 4
HOLD_HOLD = 5


class ButtonTargetType(Enum):
RESERVED1 = 0
RESERVED2 = 1
RELAYS = 2
DEVICE = 3
LOCATION = 4
GROUP = 5
SCENE = 6
DEVICE_RELAYS = 7


class Services(Enum):
UDP = 1
RESERVED1 = 2
Expand Down
53 changes: 53 additions & 0 deletions modules/photons_messages/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ def multizone_effect_parameters_for(typ):

# fmt: off


def union_fields_ButtonTarget(typ):
if typ is enums.ButtonTargetType.RESERVED6:
yield from (("reserved6", T.Reserved(128)), )
if typ is enums.ButtonTargetType.RESERVED7:
yield from (("reserved7", T.Reserved(128)), )
if typ is enums.ButtonTargetType.RELAYS:
yield from (*button_target_relays, )
if typ is enums.ButtonTargetType.DEVICE:
yield from (*button_target_device, )
if typ is enums.ButtonTargetType.LOCATION:
yield from (("location", T.Bytes(16 * 8)), )
if typ is enums.ButtonTargetType.GROUP:
yield from (("group", T.Bytes(16 * 8)), )
if typ is enums.ButtonTargetType.SCENE:
yield from (("scene", T.Bytes(16 * 8)), )
if typ is enums.ButtonTargetType.DEVICE_RELAYS:
yield from (*button_target_device_relays, )


duration_type = T.Uint32.default(0).transform(
lambda _, value: int(1000 * float(value))
, lambda _, value: float(value) / 1000
Expand Down Expand Up @@ -68,6 +88,39 @@ def multizone_effect_parameters_for(typ):
, ("kelvin", T.Uint16.optional())
]

button_target_relays = [
("relays_count", T.Uint8)
, ("relays", T.Uint8.multiple(15))
]

button_target_device = [
("serial", T.Bytes(6 * 8))
, ("reserved6", T.Reserved(80))
]

button_target_device_relays = [
("serial", T.Bytes(6 * 8))
, ("relays_count", T.Uint8)
, ("relays", T.Uint8.multiple(9))
]

button_action = [
("gesture", T.Uint16.enum(enums.ButtonGesture))
, ("target_type", T.Uint16.enum(enums.ButtonTargetType))
, ("target", T.Bytes(16 * 8).dynamic(lambda pkt: fields.union_fields_ButtonTarget(pkt.target_value)))
]

class ButtonAction(dictobj.PacketSpec):
fields = button_action

button = [
("actions_count", T.Uint8)
, ("actions", T.Bytes(160).multiple(5, kls=ButtonAction))
]

class Button(dictobj.PacketSpec):
fields = button

hsbk = [
("hue", scaled_hue)
, ("saturation", scaled_to_65535)
Expand Down
47 changes: 47 additions & 0 deletions modules/photons_messages/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,52 @@ class LightMessages(Messages):
, ("result", T.Uint8.enum(enums.LightLastHevCycleResult))
)

########################
### BUTTON
########################

class ButtonMessages(Messages):
GetButton = msg(905)

SetButton = msg(906
, ("button_index", T.Uint8)
, ("buttons_count", T.Uint8)
, ("buttons", T.Bytes(808).multiple(8, kls=fields.Button))
)

ButtonState = msg(907
, ("total_count", T.Uint8)
, ("button_index", T.Uint8)
, ("buttons_count", T.Uint8)
, ("buttons", T.Bytes(808).multiple(8, kls=fields.Button))
)

GetConfig = msg(909)

SetConfig = msg(910
, ("haptic_duration_ms", T.Uint16)
, ("backlight_on_color_hue", T.Uint16)
, ("backlight_on_color_saturation", T.Uint16)
, ("backlight_on_color_brightness", T.Uint16)
, ("backlight_on_color_kelvin", T.Uint16)
, ("backlight_off_color_hue", T.Uint16)
, ("backlight_off_color_saturation", T.Uint16)
, ("backlight_off_color_brightness", T.Uint16)
, ("backlight_off_color_kelvin", T.Uint16)
)

StateConfig = msg(911
, ("haptic_duration_ms", T.Uint16)
, ("backlight_on_color_hue", T.Uint16)
, ("backlight_on_color_saturation", T.Uint16)
, ("backlight_on_color_brightness", T.Uint16)
, ("backlight_on_color_kelvin", T.Uint16)
, ("backlight_off_color_hue", T.Uint16)
, ("backlight_off_color_saturation", T.Uint16)
, ("backlight_off_color_brightness", T.Uint16)
, ("backlight_off_color_kelvin", T.Uint16)
)

########################
### MULTI_ZONE
########################
Expand Down Expand Up @@ -388,6 +434,7 @@ class TileMessages(Messages):
"DiscoveryMessages",
"DeviceMessages",
"LightMessages",
"ButtonMessages",
"MultiZoneMessages",
"RelayMessages",
"TileMessages",
Expand Down
26 changes: 26 additions & 0 deletions tools/generate_photons_messages/adjustments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ignore:
MultiZoneEffectParameter: {}
TileAccelMeas:
expanded: true
ButtonBacklightHsbk:
expanded: true

output:
- create: enums
Expand Down Expand Up @@ -178,6 +180,30 @@ clones:
more_extras: ["optional()"]

changes:
ButtonAction:
fields:
Target:
union_enum: ButtonTargetType
union_switch_field: target_value
multi_options:
name: ButtonAction

Button:
multi_options:
name: Button

ButtonSet:
fields:
Index:
rename: button_index

ButtonState:
fields:
Index:
rename: button_index
Count:
rename: total_count

DeviceStateUnhandled:
namespace: core

Expand Down
2 changes: 1 addition & 1 deletion tools/generate_photons_messages/public-protocol
Submodule public-protocol updated 1 files
+210 −1 protocol.yml

0 comments on commit 125e54e

Please sign in to comment.