Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

share device name in gateway_suscribe_attributes or all/device attributes #23

Open
FarfadetMrs opened this issue Jul 27, 2022 · 0 comments

Comments

@FarfadetMrs
Copy link

Hi there !

I'm currently using the python client sdk and i found a missing item. So maybe i'm not using correctly the SDK but when my gateway device TBGatewayMqttClient suscribe for attribute with gw_subscribe_to_attribute, the device name is not shared to the callback.
This is a problem for me because when i modify an attribute on TB dashboard i get the new attribute name : value but i do not get the device corresponding.

In tb_gateway_mqtt.py i had to make a modification in method called "_on_decoded_message" to make this happened :

`elif message.topic == GATEWAY_ATTRIBUTES_TOPIC:

        with self._lock:
            # callbacks for everything
            if self.__sub_dict.get("*|*"):
                for callback in self.__sub_dict["*|*"]:
                    self.__sub_dict["*|*"][callback](self, content["data"])
            # callbacks for device. in this case callback executes for all attributes in message
            target = content["device"] + "|*"
            if self.__sub_dict.get(target):
                for callback in self.__sub_dict[target]:
                    self.__sub_dict[target][callback](self, content["data"])
            # callback for atr. in this case callback executes for all attributes in message
            targets = [content["device"] + "|" + callback for callback in content["data"]]
            for target in targets:
                if self.__sub_dict.get(target):
                    for sub_id in self.__sub_dict[target]:
                        self.__sub_dict[target][sub_id](self, content["data"])`

to

`elif message.topic == GATEWAY_ATTRIBUTES_TOPIC:

        with self._lock:
            # callbacks for everything
            if self.__sub_dict.get("*|*"):
                for callback in self.__sub_dict["*|*"]:
                    self.__sub_dict["*|*"][callback](self, content["device"], content["data"])
            # callbacks for device. in this case callback executes for all attributes in message
            target = content["device"] + "|*"
            if self.__sub_dict.get(target):
                for callback in self.__sub_dict[target]:
                    self.__sub_dict[target][callback](self, content["device"], content["data"])
            # callback for atr. in this case callback executes for all attributes in message
            targets = [content["device"] + "|" + callback for callback in content["data"]]
            for target in targets:
                if self.__sub_dict.get(target):
                    for sub_id in self.__sub_dict[target]:
                        self.__sub_dict[target][sub_id](self, content["device"], content["data"])`

adding content["device"] allows me to get the device name in the callback and execute correspond process for this particular device. Is there another way to get the same result or do you think this modification has to be implemented ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant