@@ -226,7 +226,7 @@ def init_config():
226226
227227# Initialize MQTT client connection
228228def init_mqtt_client ():
229- global MQTT_CLIENT , CONFIG , LOGGER
229+ global MQTT_CLIENT
230230 # Used for alternate MQTT connection method
231231 mqtt .Client .connected_flag = False
232232
@@ -264,7 +264,7 @@ def retry_if_io_error(exception):
264264# Initialize USB dongle
265265@retry (wait_exponential_multiplier = 1000 , wait_exponential_max = 30000 , retry_on_exception = retry_if_io_error )
266266def init_wyzesense_dongle ():
267- global WYZESENSE_DONGLE , CONFIG , LOGGER
267+ global WYZESENSE_DONGLE
268268 if (CONFIG ['usb_dongle' ].lower () == "auto" ):
269269 device_list = subprocess .check_output (["ls" , "-la" , "/sys/class/hidraw" ]).decode ("utf-8" ).lower ()
270270 for line in device_list .split ("\n " ):
@@ -405,7 +405,6 @@ def valid_sensor_mac(sensor_mac):
405405
406406# Add sensor to config
407407def add_sensor_to_config (sensor_mac , sensor_type = None , sensor_version = None ):
408- global SENSORS , SENSORS_STATE
409408 LOGGER .info (f"Adding sensor to config: { sensor_mac } " )
410409 SENSORS [sensor_mac ] = {'name' : f"WyzeSense { sensor_mac } " }
411410 if sensor_type :
@@ -427,7 +426,6 @@ def add_sensor_to_config(sensor_mac, sensor_type=None, sensor_version=None):
427426
428427# Delete sensor from config
429428def delete_sensor_from_config (sensor_mac ):
430- global SENSORS , SENSORS_STATE
431429 LOGGER .info (f"Deleting sensor from config: { sensor_mac } " )
432430 try :
433431 del SENSORS [sensor_mac ]
@@ -439,7 +437,6 @@ def delete_sensor_from_config(sensor_mac):
439437
440438# Publish MQTT topic
441439def mqtt_publish (mqtt_topic , mqtt_payload , is_json = True , wait = True ):
442- global MQTT_CLIENT , CONFIG
443440 payload = json .dumps (mqtt_payload ) if is_json else mqtt_payload
444441 LOGGER .debug (f"Publishing, { mqtt_topic = } , { payload = } " )
445442 mqtt_message_info = MQTT_CLIENT .publish (
@@ -458,8 +455,6 @@ def mqtt_publish(mqtt_topic, mqtt_payload, is_json=True, wait=True):
458455
459456# Send discovery topics
460457def send_discovery_topics (sensor_mac , wait = True ):
461- global SENSORS , CONFIG , SENSORS_STATE
462-
463458 LOGGER .info (f"Publishing discovery topics for { sensor_mac } " )
464459
465460 sensor = SENSORS [sensor_mac ]
@@ -644,7 +639,6 @@ def send_discovery_topics(sensor_mac, wait=True):
644639
645640# Clear any retained topics in MQTT
646641def clear_topics (sensor_mac , wait = True ):
647- global CONFIG
648642 LOGGER .info ("Clearing sensor topics" )
649643 mqtt_publish (f"{ CONFIG ['self_topic_root' ]} /{ sensor_mac } /status" , None , wait = wait )
650644 mqtt_publish (f"{ CONFIG ['self_topic_root' ]} /{ sensor_mac } " , None , wait = wait )
@@ -673,7 +667,6 @@ def clear_topics(sensor_mac, wait=True):
673667 mqtt_publish (f"{ CONFIG ['hass_topic_root' ]} /{ component } /wyzesense_{ sensor_mac } " , None , wait = wait )
674668
675669def on_connect (MQTT_CLIENT , userdata , flags , rc ):
676- global CONFIG
677670 if rc == mqtt .MQTT_ERR_SUCCESS :
678671 MQTT_CLIENT .subscribe (
679672 [(SCAN_TOPIC , CONFIG ['mqtt_qos' ]),
@@ -704,7 +697,6 @@ def on_message(MQTT_CLIENT, userdata, msg):
704697
705698# Process message to scan for new sensors
706699def on_message_scan (MQTT_CLIENT , userdata , msg ):
707- global SENSORS , CONFIG
708700 result = None
709701 LOGGER .info (f"In on_message_scan: { msg .payload .decode ()} " )
710702
@@ -763,8 +755,6 @@ def on_message_reload(MQTT_CLIENT, userdata, msg):
763755
764756# Process event
765757def on_event (WYZESENSE_DONGLE , event ):
766- global SENSORS , SENSORS_STATE
767-
768758 if not INITIALIZED :
769759 return
770760
0 commit comments