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

add property_action? #74

Open
hidaris opened this issue Jun 5, 2020 · 1 comment
Open

add property_action? #74

hidaris opened this issue Jun 5, 2020 · 1 comment

Comments

@hidaris
Copy link

hidaris commented Jun 5, 2020

In some scenarios, such as switching lights on and off, we need to do something extra to synchronize the state with the device after updating the properties, but webthing-python doesn't seem to implement this feature, I add this in aiowebthing, property:

async def property_action(self, property_):
     """
     Additional action when a property change.
     property_ -- the property that changed
     """
     pass

usage example:

class Z2mThing(Thing):
    async def property_action(self, property_):
        if property_.name == "state":
            value = "ON" if await property_.get_value() else "OFF"
        else:
            value = await property_.get_value()
        await mqtt.publish(f"zigbee2mqtt/{self.id}/set", {property_.name: value})
@mrstegeman
Copy link
Contributor

Couldn't this all be done as part of the value_forwarder callback in the Value class?

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

2 participants