@@ -317,7 +317,7 @@ def _set_mqtt_connection_status(self, status: MqttConnectionStatus):
317317 def _on_message (self , client , userdata , msg ):
318318 # print("got a message: {}: {}".format(msg.topic, msg.payload))
319319 # TODO Handle json_key writes. https://github.com/tjhowse/modbus4mqtt/issues/23
320- topic = msg .topic [len (self .prefix ) :]
320+ topic = msg .topic [len (self .prefix ):]
321321 for register in [
322322 register for register in self .registers if "set_topic" in register
323323 ]:
@@ -424,9 +424,15 @@ def _validate_registers(registers):
424424 )
425425 )
426426
427- def _load_modbus_config (self , path ) :
427+ def _load_modbus_config (self , path : str ) -> dict :
428428 yaml = YAML (typ = "safe" )
429- result = yaml .load (open (path , "r" ).read ())
429+ try :
430+ result = yaml .load (open (path , "r" ).read ())
431+ except FileNotFoundError :
432+ # Try to load the config from the pre-1.0.0 location. I.E. replace "config" with "modbus4mqtt"
433+ alt_path = path .replace ("config" , "modbus4mqtt" )
434+ logging .warning ("Failed to find config file on path: {}. Checking alternative path {}" .format (path , alt_path ))
435+ result = yaml .load (open (alt_path , "r" ).read ())
430436 registers = [
431437 register for register in result ["registers" ] if "pub_topic" in register
432438 ]
0 commit comments