File tree Expand file tree Collapse file tree
MacroPad_RPC_Home_Assistant Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ class MqttError(Exception):
4848def rpc_call (function , * args , ** kwargs ):
4949 response = rpc .call (function , * args , ** kwargs )
5050 if response ["error" ]:
51- if response ["error_type" ]:
51+ if response ["error_type" ] == "mqtt" :
5252 raise MqttError (response ["message" ])
5353 raise RpcError (response ["message" ])
5454 return response ["return_val" ]
@@ -64,6 +64,15 @@ def update_key(key_number):
6464 else :
6565 macropad .pixels [key_number ] = 0
6666
67+ server_is_running = False
68+ print ("Waiting for server..." )
69+ while not server_is_running :
70+ try :
71+ server_is_running = rpc_call ("is_running" )
72+ print ("Connected" )
73+ except RpcError :
74+ pass
75+
6776mqtt_init ()
6877last_macropad_encoder_value = macropad .encoder
6978
Original file line number Diff line number Diff line change @@ -68,10 +68,14 @@ def mqtt_get_last_value(topic):
6868 return last_mqtt_messages [topic ]
6969 return None
7070
71+ def is_running ():
72+ return True
73+
7174def handle_rpc (packet ):
7275 """This function will verify good data in packet,
7376 call the method with parameters, and generate a response
7477 packet as the return value"""
78+ print ("Received packet" )
7579 func_name = packet ['function' ]
7680 if func_name in PROTECTED_FUNCTIONS :
7781 return rpc .create_response_packet (error = True , message = f"{ func_name } '() is a protected function and can not be called." )
You can’t perform that action at this time.
0 commit comments