@@ -135,6 +135,10 @@ def __init__(self, config=None):
135135 self .brightness_ticker = LoopingCall (self .ticker_brightness_ctrl )
136136 self .brightness_ticker .start (.1 )
137137
138+ self .brightness_pub_ticker = LoopingCall (self .global_brightness_publish )
139+ self .brightness_pub_ticker .start (5 )
140+
141+ # brightness control via pubsub listeners, unlike original la4 machine which is/was an rpc call
138142 def ticker_brightness_ctrl (self ):
139143 if self .brightness_act != self .brightness_tgt .value :
140144 if self .brightness_act < self .brightness_tgt .value :
@@ -152,33 +156,34 @@ def run_brightness_on_val(self, val):
152156
153157 return res
154158
155- # brightness control (todo, rework this overall interface)
156159 @inlineCallbacks
157160 def global_brightness_publish (self ):
158- yield self .publish ("com.lambentri.edge.la4.machine.gb" , brightness = self .brightness_tgt .value )
159-
160- @wamp .register ("com.lambentri.edge.la4.machine.gb.up" , options = RegisterOptions ())
161- def global_brightness_value_up (self ):
162- """Move the global brightness up a single tick"""
163- self .brightness_tgt = self .brightness_tgt .next_up (self .brightness_tgt )
164- self .global_brightness_publish ()
165- return {"brightness" : self .brightness_tgt .value }
166-
167- @wamp .register ("com.lambentri.edge.la4.machine.gb.dn" )
168- def global_brightness_value_dn (self ):
169- """Move the global brightness down a single tick"""
170- self .brightness_tgt = self .brightness_tgt .next_dn (self .brightness_tgt )
171- self .global_brightness_publish ()
172- return {"brightness" : self .brightness_tgt .value }
173-
174- @wamp .register ("com.lambentri.edge.la4.machine.gb.set" )
175- def global_brightness_value_set (self , value : int ):
176- """Set the global brightness"""
177- self .brightness_tgt = BrightnessEnum (value )
178- self .global_brightness_publish ()
179- return {"brightness" : self .brightness_tgt .value }
180-
181- @wamp .register ("com.lambentri.edge.la4.machine.gb.get" )
182- def global_brightness_value_get (self ):
161+ yield self .publish ("com.lambentri.edge.la4.machine.gb" ,
162+ brightness = self .brightness_tgt .value ,
163+ cls = self .cconfig .machine_name )
164+
165+ @wamp .subscribe ("com.lambentri.edge.la4.machine.gb.up" )
166+ def brightness_value_up (self , cls : str , globl : bool = False ):
167+ """Move the brightness up a single tick"""
168+ if cls == self .cconfig .machine_name or globl :
169+ self .brightness_tgt = self .brightness_tgt .next_up (self .brightness_tgt )
170+ self .global_brightness_publish ()
171+
172+ @wamp .subscribe ("com.lambentri.edge.la4.machine.gb.dn" )
173+ def brightness_value_dn (self , cls : str , globl : bool = False ):
174+ """Move the brightness down a single tick"""
175+ if cls == self .cconfig .machine_name or globl :
176+ self .brightness_tgt = self .brightness_tgt .next_dn (self .brightness_tgt )
177+ self .global_brightness_publish ()
178+
179+ @wamp .subscribe ("com.lambentri.edge.la4.machine.gb.set" )
180+ def brightness_value_set (self , cls : str , value : int , globl : bool = False ):
181+ """Set the brightness"""
182+ if cls == self .cconfig .machine_name or globl :
183+ self .brightness_tgt = BrightnessEnum (value )
184+ self .global_brightness_publish ()
185+
186+ @wamp .subscribe ("com.lambentri.edge.la4.machine.gb.get" )
187+ def brightness_value_get (self ):
183188 """get the global brightness"""
184- return {"brightness" : self .brightness_tgt .value }
189+ return {"brightness" : self .brightness_tgt .value , "cls" : self . cconfig . machine_name }
0 commit comments