Devices¶
hassdevice.devices¶
-
class
hassdevice.devices.
Switch
(name, entity_id)[source]¶ An MQTT switch
-
__init__
(name, entity_id)[source]¶ Parameters: - name – The display name to use in HomeAssistant
- entity_id – The entity_id to use in HomeAssistant
-
base_topic
¶
-
command_topic
¶
-
config
¶
-
config_topic
¶
-
connect
(mqtt_client, discovery_prefix='homeassistant', node_id=None)[source]¶ Connect this device to an MQTT broker
Parameters: - mqtt_client – A connected MQTT client
- discovery_prefix – The discovery prefix set in the HomeAssistant config
- node_id – Will be included in the MQTT topics if set
-
on_state_change
(new_state)[source]¶ Called when a state update request is recieved from the broker
Parameters: new_state – The state to set
-
payload_off
¶ Payload to use to indicate the switch is off. Defaults to
"OFF"
-
payload_on
¶ Payload to use to indicate the switch is on. Defaults to
"ON"
-
retain
¶ Should the messages sent to the broker have the ‘retain’ flag set. Defaults to
True
-
state
¶ The state of the switch. Must be one of
self.payload_on
orself.payload_off
Getter: The last state the switch was set to (May be None
if the state has never been set)Setter: Record the state change, and report it to the broker
-
state_topic
¶
-