Skip to content

Commit

Permalink
animation state system
Browse files Browse the repository at this point in the history
  • Loading branch information
meowmeowahr committed Feb 25, 2024
1 parent b0ef970 commit d91fa42
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ mqtt:
state_topic: "MQTTAnimator/state"
return_state_topic: "MQTTAnimator/rstate"
brightness_topic: "MQTTAnimator/brightness"
breturn_rightness_topic: "MQTTAnimator/rbrightness"
return_brightness_topic: "MQTTAnimator/rbrightness"
return_anim_topic: "MQTTAnimator/ranimation"
args_topic: "MQTTAnimator/args"
animation_topic: "MQTTAnimator/animation"
reconnection:
Expand Down
5 changes: 4 additions & 1 deletion mqtt_animator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
data_request_return_topic: str = mqtt_topics.get("return_data_request_topic",
"MQTTAnimator/rdata_request")
state_return_topic: str = mqtt_topics.get("return_state_topic", "MQTTAnimator/rstate")
anim_return_topic: str = mqtt_topics.get("return_anim_topic", "MQTTAnimator/ranimation")
brightness_return_topic: str = mqtt_topics.get("return_brightness_topic",
"MQTTAnimator/rbrightness")

Expand Down Expand Up @@ -113,7 +114,8 @@ def on_message(cli: mqtt_client.Client, __, msg):
if msg.topic == data_request_topic:
cli.publish(data_request_return_topic,
json.dumps({"state": animation_state.state,
"brightness": animation_state.brightness}))
"brightness": animation_state.brightness,
"animation": animation_state.effect}))
elif msg.topic == state_topic:
animation_state.state = "ON" if msg.payload.decode() == "ON" else "OFF"
cli.publish(state_return_topic, "ON" if msg.payload.decode() == "ON" else "OFF")
Expand All @@ -125,6 +127,7 @@ def on_message(cli: mqtt_client.Client, __, msg):
logging.warning("Invalid brightness data: %s", msg.payload.decode())
elif msg.topic == animation_topic:
animation_state.effect = msg.payload.decode()
cli.publish(anim_return_topic, animation_state.effect)
elif msg.topic == args_topic:
animation, data = msg.payload.decode().split(",", maxsplit=1)
data = json.loads(data)
Expand Down

0 comments on commit d91fa42

Please sign in to comment.