diff --git a/README.md b/README.md index 0ebf4bd..0b5590b 100644 --- a/README.md +++ b/README.md @@ -318,7 +318,7 @@ my_light.off() ### Covers -A cover has four possible states `open`, `closed`, `opening`, `closing` and `stopped`. Most other entities use the states as command payload, but covers differentiate on this. The user HA user can either open, close or stop it in the covers current position. +A cover has five possible states `open`, `closed`, `opening`, `closing` and `stopped`. Most other entities use the states as command payload, but covers differentiate on this. The user HA user can either open, close or stop it in the covers current position. Covers do not currently support tilt. @@ -328,7 +328,49 @@ example shows: #### Usage ```py +from ha_mqtt_discoverable import Settings +from ha_mqtt_discoverable.sensors import Cover, CoverInfo +from paho.mqtt.client import Client, MQTTMessage + +# Configure the required parameters for the MQTT broker +mqtt_settings = Settings.MQTT(host="localhost") + +# Information about the cover +cover_info = CoverInfo(name="test") + +settings = Settings(mqtt=mqtt_settings, entity=cover_info) + +# To receive state commands from HA, define a callback function: +def my_callback(client: Client, user_data, message: MQTTMessage): + payload = message.payload.decode() + if payload == "OPEN": + # let HA know that the cover is opening + my_cover.opening() + # call function to open cover + open_my_custom_cover() + # Let HA know that the cover was opened + my_cover.open() + if payload == "CLOSE": + # let HA know that the cover is closing + my_cover.closing() + # call function to close the cover + close_my_custom_cover() + # Let HA know that the cover was closed + my_cover.closed() + if payload == "STOP": + # call function to stop the cover + stop_my_custom_cover() + # Let HA know that the cover was stopped + my_cover.stopped() + +# Define an optional object to be passed back to the callback +user_data = "Some custom data" + +# Instantiate the cover +my_cover = Cover(settings, my_callback, user_data) +# Set the initial state of the cover, which also makes it discoverable +my_cover.closed() ``` ### Text