Skip to content

Commit d7f8682

Browse files
committed
example of a binary_sensor with some branding on the device_info
1 parent cea5377 commit d7f8682

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

examples/branded_binary_sensor.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
"""Example of a binary sensor with some device branding."""
3+
4+
from ham import MqttManager
5+
from ham.binary_sensor import BinarySensor
6+
from time import sleep
7+
import os
8+
9+
MQTT_USERNAME = os.environ["MQTT_USERNAME"]
10+
MQTT_PASSWORD = os.environ["MQTT_PASSWORD"]
11+
MQTT_HOST = os.environ["MQTT_HOST"]
12+
13+
14+
class IsTurnedOn(BinarySensor):
15+
name = "Is this turned on?"
16+
short_id = "turned_on"
17+
18+
19+
if __name__ == "__main__":
20+
bs = IsTurnedOn()
21+
manager = MqttManager(MQTT_HOST, username=MQTT_USERNAME, password=MQTT_PASSWORD)
22+
manager.device_info["manufacturer"] = "AwesomeM"
23+
manager.device_info["model"] = "ScrapPilePC"
24+
25+
manager.add_thing(bs)
26+
27+
manager.start()
28+
29+
print("Entering an infinite loop, Ctrl+C multiple times to exit.")
30+
while True:
31+
sleep(5)
32+
bs.state = True

0 commit comments

Comments
 (0)