smarthomeNG / smarthome

Device integration platform for your smart home
https://www.smarthomeNG.de
GNU General Public License v3.0
123 stars 92 forks source link

mqtt: subscription from logic never triggered #450

Closed CodeRed4 closed 2 years ago

CodeRed4 commented 2 years ago

Trying to subscribe to a MQTT topic out of an own logic code I realized that callback never gets called. Test was done with 1.9.0 but seems to happen also with 1.8.2

Enabling some debug logging you can see that caller-type not being recognized as "Logic" but "Unknown"

Logging output at subscription

DEBUG modules.mqtt _get_caller_type: inspect.stack()[2][1] = '/usr/local/smarthome_1.9.0/logics/kiosk.py', split = ['', 'usr', 'local', 'smarthome_1.9.0', 'logics', 'kiosk.py']
INFO modules.mqtt _get_caller_type: inspect.stack()[2][1] = '/usr/local/smarthome_1.9.0/logics/kiosk.py', split = ['', 'usr', 'local', 'smarthome_1.9.0', 'logics', 'kiosk.py']
DEBUG modules.mqtt 'subscribe_topic()' - called from Unknown by '()'
INFO modules.mqtt subscribe_topic: Adding topic 'fully/event/screenOn'
INFO modules.mqtt _add_subscription_definition: Unknown 'kiosk_browser' is subscribing to topic 'fully/event/screenOn'
INFO modules.mqtt subscribe_topic: mqtt module is subscribing to topic 'fully/event/screenOn' with qos=1 at broker (result=0, mid=29)

Logging output when topic received

DEBUG modules.mqtt _on_mqtt_message: RECEIVED topic 'fully/event/screenOn', payload 'b'{"deviceId":"xxxxxxx","event":"screenOn"}', QoS '1', retain '0'
DEBUG modules.mqtt _on_mqtt_message: subscription 'kiosk_browser': {'subscriber_type': 'unknown', 'callback': 'kiosk_browser', 'payload_type': 'str', 'bool_values': None}
ERROR modules.mqtt _on_mqtt_message: received topic for unknown subscriber_type 'unknown'
ERROR modules.mqtt _on_mqtt_message: Received topic 'fully/event/screenOn', payload 'b'{"deviceId":"xxxxxxx","event":"screenOn"}'', QoS '1', retain '0' WITHOUT matching item/logic

I was able to fix the issue for my szenario by updating an array-index within modules/mqtt/init.py:728 function _get_caller_type instead of elif split[-3] == 'logics' use elif split[-2] == 'logics'

msinn commented 2 years ago

Fixed fix https://github.com/smarthomeNG/smarthome/commit/3d248785aa493f62adc2e3566b28e147fb59ce56

msinn commented 2 years ago

Fixed with the release 1.9.1