Giter Site home page Giter Site logo

Comments (4)

Adair-GA avatar Adair-GA commented on August 15, 2024 1

Oh, okay, I wasn't aware that I could access the value field like that.
Kind of guilty of not reading the docs and relying on Intellisense πŸ˜….
Great work with this library, it's really useful, and thanks for the pleasant response!

from aiomqtt.

empicano avatar empicano commented on August 15, 2024

Hi there! 😊 It's not entirely clear to me from your description why your code was not working, or what changes you are suggesting. Could you post a minimal working example?

from aiomqtt.

Adair-GA avatar Adair-GA commented on August 15, 2024

This is the code I was using:

if message.topic == "/app/device/property/DAEBZ5KEB033484":
      await sio.emit('delta', message.payload)
elif message.topic == "/app/device/property/R601ZEB5HF260973":
      await sio.emit('river', message.payload)

and it wasn't working, the condition was never true, so I changed the == to message.topic.matches(), like this

if message.topic.matches("/app/device/property/DAEBZ5KEB033484"):
      await sio.emit('delta', message.payload)
elif message.topic.matches("/app/device/property/R601ZEB5HF260973"):
      await sio.emit('river', message.payload)

My suggestion is for == to do the same as .matches(), if no other case requieres the == comparation to be what it is now

from aiomqtt.

empicano avatar empicano commented on August 15, 2024

Thanks for the example! πŸ‘

Topic.matches() can match filters as well, so something like Topic("a/b/c").matches("a/+/c") returns true, as shown in the Filtering messages section in our docs. If you want, you can access the topic string directly via Topic.value.

Replacing Topic.matches() entirely by == (by implementing __eq__ for Topic) would lead to something unexpected, namely that Topic("a/b/c") == "a/+/c" would return true and "a/+/c" == Topic("a/b/c") would return false.

Does that make sense? πŸ™‚

from aiomqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.