Skip to content

Commit

Permalink
Merge pull request #145 from wtahler/patch-1
Browse files Browse the repository at this point in the history
added cover example
  • Loading branch information
unixorn authored Nov 30, 2023
2 parents 339de21 + 0b78b0f commit fbc47b0
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down

0 comments on commit fbc47b0

Please sign in to comment.