def close_door(self): """Close the door.""" mqtt.publish(self.hass, self._command_topic, self._service_close, self._qos, self._retain) if self._optimistic: # Optimistically assume that door has changed state. self._state = False self.update_ha_state()
def _publish_temperature(self): if self._target_temperature is None: return unencoded = '{"temperature":' + str(round( self._target_temperature)) + '}' mqtt.publish(self.hass, self._command_topic, unencoded, self._qos, self._retain)
def open_door(self): """Open the door.""" mqtt.publish(self.hass, self._command_topic, self._service_open, self._qos, self._retain) if self._optimistic: # Optimistically assume that door has changed state. self._state = True self.update_ha_state()
def mqttPublish(self, topic=None, payload=None, qos=None, retain=None): if topic is None: topic = self._mqttTopic + '/unknown' if payload is None: payload = "" else: if isinstance(payload, bytes): payload = payload.decode() if qos is None: qos = self._qos if retain is None: retain = False if mqtt: mqtt.publish(hass=self.hass, topic=topic, payload=payload, qos=qos, retain=retain) self._lastMQTTOut = { 'topic': topic, 'payload': payload, 'ts': time.time() } else: _LOGGER.error("No MQTT Send to %s. MQTT is not available." % topic) self.schedule_update_ha_state()
def update_temperature_humidity(self, now=None): #check if battery level out of date if not (self._temperature_sensor.device_state_attributes[ATTR_BATTERY] and self._humidity_sensor.device_state_attributes[ATTR_BATTERY]): _LOGGER.info("update meizu battery because it's out of date") self.update_battery_level() payload = '85,3,8,17' sub_topic = self._mac_address + self._topic pub_topic = sub_topic + self._set_suffix mqtt.publish(self._hass, pub_topic, payload) @callback def msg_callback(msg): """Receive events published by and fire them on this hass instance.""" results = msg.payload.split(',') # 返回数据8位是温湿度信息, 45位温度,67位是湿度,85,7,8,17,211,11,239,25 if len(results) == 8 and int(results[0]) == 85 and int( results[1]) == 7 and int(results[2]) == 8 and int( results[3]) == 17: temperature = round( (int(results[4]) + int(results[5]) * 16 * 16) / 100, 1) humidity = round( (int(results[6]) + int(results[7]) * 16 * 16) / 100, 1) self._temperature_sensor.update_state(temperature) self._humidity_sensor.update_state(humidity) mqtt.subscribe(self._hass, sub_topic, msg_callback)
def alarm_disarm(self, code=None): """ Send disarm command. """ if code == str(self._code) or self.code_format is None: mqtt.publish(self.hass, self._command_topic, self._payload_disarm, self._qos) else: _LOGGER.warning("Wrong code entered while disarming!")
def turn_off(self, **kwargs): """ Turn the device off. """ mqtt.publish(self.hass, self._command_topic, self._payload_off) if self._optimistic: # optimistically assume that switch has changed state self._state = False self.update_ha_state()
def alarm_arm_away(self, code=None): """ Send arm away command. """ if code == str(self._code) or self.code_format is None: mqtt.publish(self.hass, self._command_topic, self._payload_arm_away, self._qos) else: _LOGGER.warning("Wrong code entered while arming away!")
def update(self): """Update the data from the thermostat.""" _LOGGER.info("Update called {}".format(self._mac)) # send update request cmds_connect = { 'tries': 5, 'commands': [ { 'action': 'writeCharacteristic', 'uuid': UUID_PIN, 'value': [ int(x) for x in self._pin.to_bytes(4, byteorder = 'little') ] }, ] } cmds_set = copy.deepcopy(cmds_connect) if self._current.mode_code != self._target.mode_code and self._target.manual is not None: cmds_set['commands'].append({ 'action': 'writeCharacteristic', 'uuid': UUID_MODE, 'value': [ self._target.mode_value, 0, 0 ] }) if self._current.target_temp != self._target.target_temp and self._target.target_temp is not None: cmds_set['commands'].append({ 'action': 'writeCharacteristic', 'uuid': UUID_TEMP, 'value': [ 128, int(self._target.target_temp * 2), 128, 128, 128, 128, 128 ] }) if len(cmds_set['commands']) > 1: mqtt.publish(self.hass, 'ble/{}/commands'.format(self._mac), json.dumps(cmds_set), 1, False) cmds_get = copy.deepcopy(cmds_connect) cmds_get['commands'].append({ 'action': 'readCharacteristic', 'uuid': UUID_MODE }) cmds_get['commands'].append({ 'action': 'readCharacteristic', 'uuid': UUID_TEMP }) cmds_get['commands'].append({ 'action': 'readCharacteristic', 'uuid': UUID_BATTERY }) if self._current.model_no is None: cmds_get['commands'].append({ 'action': 'readCharacteristic', 'uuid': UUID_MODEL }) cmds_get['commands'].append({ 'action': 'readCharacteristic', 'uuid': UUID_FIRMWARE }) cmds_get['commands'].append({ 'action': 'readCharacteristic', 'uuid': UUID_SOFTWARE }) cmds_get['commands'].append({ 'action': 'readCharacteristic', 'uuid': UUID_MANU }) mqtt.publish(self.hass, 'ble/{}/commands'.format(self._mac), json.dumps(cmds_get), 1, False)
def unlock(self, **kwargs): """Unlock the device.""" mqtt.publish(self.hass, self._command_topic, self._payload_unlock, self._qos, self._retain) if self._optimistic: # Optimistically assume that switch has changed state. self._state = False self.update_ha_state()
def oscillate(self, oscillating: bool) -> None: """Set oscillation.""" if self._topic[CONF_SPEED_COMMAND_TOPIC] is not None: self._oscillation = oscillating mqtt.publish(self._hass, self._topic[CONF_OSCILLATION_COMMAND_TOPIC], self._oscillation, self._qos, self._retain) self.update_ha_state()
def set_fan_mode(self, fan): """Set new fan mode.""" if fan is not None: self._current_fan_mode = fan payload = '{"fan":"' + self._current_fan_mode + '"}' mqtt.publish(self.hass, self._command_topic, payload, self._qos, self._retain) self.schedule_update_ha_state()
def set_swing_mode(self, swing): """Set new swing mode.""" if swing is not None: self._current_swing_mode = swing payload = '{"vane":"' + self._current_swing_mode + '"}' mqtt.publish(self.hass, self._command_topic, payload, self._qos, self._retain) self.schedule_update_ha_state()
def turn_on(self, **kwargs): """Turn the device on.""" mqtt.publish(self.hass, self._command_topic, self._payload_on, self._qos, self._retain) if self._optimistic: # Optimistically assume that switch has changed state. self._state = True self.update_ha_state()
def close_cover(self, **kwargs): """Move the cover down.""" mqtt.publish(self.hass, self._command_topic, self._payload_close, self._qos, self._retain) if self._optimistic: # Optimistically assume that cover has changed state. self._state = 0 self.update_ha_state()
def open_cover(self, **kwargs): """Move the cover up.""" mqtt.publish(self.hass, self._command_topic, self._payload_open, self._qos, self._retain) if self._optimistic: # Optimistically assume that cover has changed state. self._state = False self.update_ha_state()
def open_cover(self, **kwargs): """Move the cover up.""" mqtt.publish(self.hass, self._command_topic, self._payload_open, self._qos, self._retain) if self._optimistic: # Optimistically assume that cover has changed state. self._state = False self.schedule_update_ha_state()
def turn_off(self, **kwargs): """Turn the device off.""" mqtt.publish(self._hass, self._topic["command_topic"], self._payload["off"], self._qos, self._retain) if self._optimistic: # Optimistically assume that switch has changed state. self._state = False self.update_ha_state()
def close_cover(self, **kwargs): """Move the cover down.""" mqtt.publish(self.hass, self._command_topic, self._payload_close, self._qos, self._retain) if self._optimistic: # Optimistically assume that cover has changed state. self._state = True self.update_ha_state()
def turn_on(self, **kwargs): """ Turn the device on. """ mqtt.publish(self.hass, self._command_topic, self._payload_on, self._qos, self._retain) if self._optimistic: # optimistically assume that switch has changed state self._state = True self.update_ha_state()
def turn_off(self, **kwargs): """Turn the device off.""" mqtt.publish(self._hass, self._topic[CONF_COMMAND_TOPIC], self._payload['off'], self._qos, self._retain) if self._optimistic: # Optimistically assume that switch has changed state. self._state = False self.schedule_update_ha_state()
async def async_media_play_pause(self): """Play or pause the media player.""" _LOGGER.debug( "Sending toggle play/pause command; currently %s", self._player_state ) if self._player_state == STATE_PLAYING: publish(self.hass, self._remote_topic, COMMAND_PAUSE) else: publish(self.hass, self._remote_topic, COMMAND_PLAY)
def turn_off(self, **kwargs): """Turn the device off.""" mqtt.publish(self._hass, self._topic[CONF_COMMAND_TOPIC], self._payload['off'], self._qos, self._retain) if self._optimistic: # Optimistically assume that switch has changed state. self._state = False self.update_ha_state()
def refresh(event_time): """Refresh""" result = subprocess.run([VCGENCMD_SCRIPT, 'measure_temp'], stdout=subprocess.PIPE) # _LOGGER.warn("Publish " + result.stdout.decode('utf-8')) '0001:0004:01' # result is temp=45.6'C, so need to grab the number only msg = '{{"temperature":{}}}'.format( convert_result(result.stdout.decode('utf-8'))) mqtt.publish(topic, msg) _LOGGER.info("Published " + msg)
def test_publish_calls_service(self): self.hass.bus.listen_once(EVENT_CALL_SERVICE, self.record_calls) mqtt.publish(self.hass, 'test-topic', 'test-payload') self.hass.pool.block_till_done() self.assertEqual(1, len(self.calls)) self.assertEqual('test-topic', self.calls[0][0].data[mqtt.ATTR_TOPIC]) self.assertEqual('test-payload', self.calls[0][0].data[mqtt.ATTR_PAYLOAD])
def save_payload_to_mqtt( self, topic, payload ): try: """mqtt.async_publish ( self.hass, topic, payload, self.mqtt_qos, self.mqtt_retain )""" _LOGGER.info("topic: %s", topic) _LOGGER.info("payload: %s", payload) mqtt.publish ( self.hass, topic, payload, self.mqtt_qos, self.mqtt_retain ) except: _LOGGER.error( "Error saving Life360 data to mqtt." )
def mute_volume(self, mute): """Mute (true) or unmute (false) media player.""" if self._mute: mqtt.publish(self.hass, self._mute_dict["command_topic"], self._mute_dict["payload_on"], self._mute_dict["qos"], self._mute_dict["retain"]) else: mqtt.publish(self.hass, self._mute_dict["command_topic"], self._mute_dict["payload_off"], self._mute_dict["qos"], self._mute_dict["retain"])
def mqtt_event_listener(event): """Listen for new messages on the bus and send data to MQTT.""" state = event.data.get("new_state") if state is None or state.state in (STATE_UNKNOWN, ""): return None PAYLOAD["states"] = hass.states.all() payload = json.dumps(PAYLOAD, cls=JSONEncoder) mqtt.publish(hass, pub_topic, payload)
def async_send_ir(self): payload = self._payload[self._speed] mqtt.publish(self.hass, self._mqtt_topic, payload) """auto close in 15mins when turn on.""" if self._speed != STATE_OFF: if self.timer is not None: if self.timer.is_alive(): self.timer.cancel() self.timer = threading.Timer(60 * 15, self.auto_turn_off) self.timer.start()
def save_payload_to_mqtt(self, topic, payload): try: """mqtt.async_publish ( self.hass, topic, payload, self.mqtt_qos, self.mqtt_retain )""" _LOGGER.debug("topic: %s", topic) _LOGGER.debug("payload: %s", payload) mqtt.publish(self.hass, topic, payload, self.mqtt_qos, self.mqtt_retain) except Exception as e: _LOGGER.error("Unable to send MQTT: %s" % e)
def oscillate(self, oscillating: bool) -> None: """Set oscillation.""" if self._topic[CONF_OSCILLATION_COMMAND_TOPIC] is not None: self._oscillation = oscillating payload = self._payload[OSCILLATE_ON_PAYLOAD] if oscillating is False: payload = self._payload[OSCILLATE_OFF_PAYLOAD] mqtt.publish(self._hass, self._topic[CONF_OSCILLATION_COMMAND_TOPIC], payload, self._qos, self._retain) self.update_ha_state()
def test_publish_calls_service(self): """Test the publishing of call to services.""" self.hass.bus.listen_once(EVENT_CALL_SERVICE, self.record_calls) mqtt.publish(self.hass, "test-topic", "test-payload") self.hass.block_till_done() self.assertEqual(1, len(self.calls)) self.assertEqual("test-topic", self.calls[0][0].data["service_data"][mqtt.ATTR_TOPIC]) self.assertEqual("test-payload", self.calls[0][0].data["service_data"][mqtt.ATTR_PAYLOAD])
def set_operation_mode(self, operation_mode): """Set new operating mode.""" self._current_operation = operation_mode if self._current_operation == "OFF": payload = '{"power":"OFF"}' self._current_power = "OFF" else: payload = '{"power":"ON","mode":"' + self._current_operation + '"}' self._current_power = "ON" mqtt.publish(self.hass, self._command_topic, payload, self._qos, self._retain) self.schedule_update_ha_state()
def async_send_calibration_to_mqtt(call): _LOGGER.warning(f"call: { call }") for entity in json.loads(hass.states.get(call.data["entities_list"]).attributes[call.data["entities_list_attribute"]]): publish(hass, hass.states.get(entity).attributes[CONF_MQTT_TOPIC], json.dumps({ key: value for key, value in enumerate(hass.states.get(entity).attributes['coefficients']) }), 1, True )
def refresh(event_time): """Refresh""" temp_parts = get_Temper2Reading() current_temperature = calc_Temperature(temp_parts) if current_temperature < MAX_TEMP: msg = '{{"temperature":{}}}'.format(current_temperature) mqtt.publish(topic, msg) _LOGGER.info("Published " + msg) else: # Sometimes the unit returns crazy values 328 deg celcius, for now we just log _LOGGER.warn( "Wrong Temperature reading [{}]".format(current_temperature))
def test_publish_calls_service(self): """Test the publishing of call to services.""" self.hass.bus.listen_once(EVENT_CALL_SERVICE, self.record_calls) mqtt.publish(self.hass, 'test-topic', 'test-payload') self.hass.block_till_done() assert 1 == len(self.calls) assert 'test-topic' == \ self.calls[0][0].data['service_data'][mqtt.ATTR_TOPIC] assert 'test-payload' == \ self.calls[0][0].data['service_data'][mqtt.ATTR_PAYLOAD]
def turn_off(self, **kwargs): """Turn the device off.""" message = {"state": "OFF"} if ATTR_TRANSITION in kwargs: message["transition"] = kwargs[ATTR_TRANSITION] mqtt.publish(self._hass, self._topic["command_topic"], json.dumps(message), self._qos, self._retain) if self._optimistic: # Optimistically assume that the light has changed state. self._state = False self.update_ha_state()
def turn_off(self, **kwargs): """Turn the device off.""" message = {'state': 'OFF'} if ATTR_TRANSITION in kwargs: message['transition'] = kwargs[ATTR_TRANSITION] mqtt.publish(self._hass, self._topic[CONF_COMMAND_TOPIC], json.dumps(message), self._qos, self._retain) if self._optimistic: # Optimistically assume that the light has changed state. self._state = False self.schedule_update_ha_state()
def set_speed(self, speed: str) -> None: """Set the speed of the fan.""" if self._topic[CONF_SPEED_COMMAND_TOPIC] is not None: mqtt_payload = SPEED_OFF if speed == SPEED_LOW: mqtt_payload = self._payload[SPEED_LOW] elif speed == SPEED_MEDIUM: mqtt_payload = self._payload[SPEED_MEDIUM] elif speed == SPEED_HIGH: mqtt_payload = self._payload[SPEED_HIGH] else: mqtt_payload = speed self._speed = speed mqtt.publish(self._hass, self._topic[CONF_SPEED_COMMAND_TOPIC], mqtt_payload, self._qos, self._retain) self.update_ha_state()
def turn_on(self, **kwargs): """Turn the device on.""" should_update = False message = {"state": "ON"} if ATTR_RGB_COLOR in kwargs: message["color"] = { "r": kwargs[ATTR_RGB_COLOR][0], "g": kwargs[ATTR_RGB_COLOR][1], "b": kwargs[ATTR_RGB_COLOR][2] } if self._optimistic: self._rgb = kwargs[ATTR_RGB_COLOR] should_update = True if ATTR_FLASH in kwargs: flash = kwargs.get(ATTR_FLASH) if flash == FLASH_LONG: message["flash"] = self._flash_times[CONF_FLASH_TIME_LONG] elif flash == FLASH_SHORT: message["flash"] = self._flash_times[CONF_FLASH_TIME_SHORT] if ATTR_TRANSITION in kwargs: message["transition"] = kwargs[ATTR_TRANSITION] if ATTR_BRIGHTNESS in kwargs: message["brightness"] = int(kwargs[ATTR_BRIGHTNESS]) if self._optimistic: self._brightness = kwargs[ATTR_BRIGHTNESS] should_update = True mqtt.publish(self._hass, self._topic["command_topic"], json.dumps(message), self._qos, self._retain) if self._optimistic: # Optimistically assume that the light has changed state. self._state = True should_update = True if should_update: self.update_ha_state()
def turn_on(self, **kwargs): """Turn the device on.""" should_update = False message = {'state': 'ON'} if ATTR_RGB_COLOR in kwargs: message['color'] = { 'r': kwargs[ATTR_RGB_COLOR][0], 'g': kwargs[ATTR_RGB_COLOR][1], 'b': kwargs[ATTR_RGB_COLOR][2] } if self._optimistic: self._rgb = kwargs[ATTR_RGB_COLOR] should_update = True if ATTR_FLASH in kwargs: flash = kwargs.get(ATTR_FLASH) if flash == FLASH_LONG: message['flash'] = self._flash_times[CONF_FLASH_TIME_LONG] elif flash == FLASH_SHORT: message['flash'] = self._flash_times[CONF_FLASH_TIME_SHORT] if ATTR_TRANSITION in kwargs: message['transition'] = kwargs[ATTR_TRANSITION] if ATTR_BRIGHTNESS in kwargs: message['brightness'] = int(kwargs[ATTR_BRIGHTNESS]) if self._optimistic: self._brightness = kwargs[ATTR_BRIGHTNESS] should_update = True mqtt.publish(self._hass, self._topic[CONF_COMMAND_TOPIC], json.dumps(message), self._qos, self._retain) if self._optimistic: # Optimistically assume that the light has changed state. self._state = True should_update = True if should_update: self.schedule_update_ha_state()
def turn_on(self, **kwargs): """Turn the entity on.""" # state values = {'state': True} if self._optimistic: self._state = True # brightness if ATTR_BRIGHTNESS in kwargs: values['brightness'] = int(kwargs[ATTR_BRIGHTNESS]) if self._optimistic: self._brightness = kwargs[ATTR_BRIGHTNESS] # color if ATTR_RGB_COLOR in kwargs: values['red'] = kwargs[ATTR_RGB_COLOR][0] values['green'] = kwargs[ATTR_RGB_COLOR][1] values['blue'] = kwargs[ATTR_RGB_COLOR][2] if self._optimistic: self._rgb = kwargs[ATTR_RGB_COLOR] # effect if ATTR_EFFECT in kwargs: values['effect'] = kwargs.get(ATTR_EFFECT) # flash if ATTR_FLASH in kwargs: values['flash'] = kwargs.get(ATTR_FLASH) # transition if ATTR_TRANSITION in kwargs: values['transition'] = kwargs[ATTR_TRANSITION] mqtt.publish( self._hass, self._topics[CONF_COMMAND_TOPIC], self._templates[CONF_COMMAND_ON_TEMPLATE].render(**values), self._qos, self._retain ) if self._optimistic: self.schedule_update_ha_state()
def turn_off(self, **kwargs): """Turn the entity off.""" # state values = {'state': False} if self._optimistic: self._state = False # transition if ATTR_TRANSITION in kwargs: values['transition'] = kwargs[ATTR_TRANSITION] mqtt.publish( self._hass, self._topics[CONF_COMMAND_TOPIC], self._templates[CONF_COMMAND_OFF_TEMPLATE].render(**values), self._qos, self._retain ) if self._optimistic: self.update_ha_state()
def turn_on(self, **kwargs): """Turn the device on.""" should_update = False if ATTR_RGB_COLOR in kwargs and \ self._topic["rgb_command_topic"] is not None: mqtt.publish(self._hass, self._topic["rgb_command_topic"], "{},{},{}".format(*kwargs[ATTR_RGB_COLOR]), self._qos) if self._optimistic_rgb: self._rgb = kwargs[ATTR_RGB_COLOR] should_update = True if ATTR_BRIGHTNESS in kwargs and \ self._topic["brightness_command_topic"] is not None: percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255 device_brightness = int(percent_bright * self._brightness_scale) mqtt.publish(self._hass, self._topic["brightness_command_topic"], device_brightness, self._qos) if self._optimistic_brightness: self._brightness = kwargs[ATTR_BRIGHTNESS] should_update = True mqtt.publish(self._hass, self._topic["command_topic"], self._payload["on"], self._qos) if self._optimistic: # Optimistically assume that switch has changed state. self._state = True should_update = True if should_update: self.update_ha_state()
def turn_on(self, **kwargs): """Turn the device on.""" should_update = False message = {"state": "ON"} if ATTR_RGB_COLOR in kwargs: message["color"] = { "r": kwargs[ATTR_RGB_COLOR][0], "g": kwargs[ATTR_RGB_COLOR][1], "b": kwargs[ATTR_RGB_COLOR][2] } if self._optimistic: self._rgb = kwargs[ATTR_RGB_COLOR] should_update = True if ATTR_TRANSITION in kwargs: message["transition"] = int(kwargs[ATTR_TRANSITION]) if ATTR_BRIGHTNESS in kwargs: message["brightness"] = int(kwargs[ATTR_BRIGHTNESS]) if self._optimistic: self._brightness = kwargs[ATTR_BRIGHTNESS] should_update = True mqtt.publish(self._hass, self._topic["command_topic"], json.dumps(message), self._qos, self._retain) if self._optimistic: # Optimistically assume that switch has changed state. self._state = True should_update = True if should_update: self.update_ha_state()
def turn_on(self, **kwargs): """Turn the device on.""" should_update = False if ATTR_RGB_COLOR in kwargs and \ self._topic[CONF_RGB_COMMAND_TOPIC] is not None: mqtt.publish(self._hass, self._topic[CONF_RGB_COMMAND_TOPIC], '{},{},{}'.format(*kwargs[ATTR_RGB_COLOR]), self._qos, self._retain) if self._optimistic_rgb: self._rgb = kwargs[ATTR_RGB_COLOR] should_update = True if ATTR_BRIGHTNESS in kwargs and \ self._topic[CONF_BRIGHTNESS_COMMAND_TOPIC] is not None: percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255 device_brightness = int(percent_bright * self._brightness_scale) mqtt.publish( self._hass, self._topic[CONF_BRIGHTNESS_COMMAND_TOPIC], device_brightness, self._qos, self._retain) if self._optimistic_brightness: self._brightness = kwargs[ATTR_BRIGHTNESS] should_update = True if ATTR_COLOR_TEMP in kwargs and \ self._topic[CONF_COLOR_TEMP_COMMAND_TOPIC] is not None: color_temp = int(kwargs[ATTR_COLOR_TEMP]) mqtt.publish( self._hass, self._topic[CONF_COLOR_TEMP_COMMAND_TOPIC], color_temp, self._qos, self._retain) if self._optimistic_color_temp: self._color_temp = kwargs[ATTR_COLOR_TEMP] should_update = True mqtt.publish(self._hass, self._topic[CONF_COMMAND_TOPIC], self._payload['on'], self._qos, self._retain) if self._optimistic: # Optimistically assume that switch has changed state. self._state = True should_update = True if should_update: self.update_ha_state()
def turn_on(self, **kwargs): """ Turn the device on. """ if ATTR_RGB_COLOR in kwargs and \ self._topic["rgb_command_topic"] is not None: self._rgb = kwargs[ATTR_RGB_COLOR] rgb = DEFAULT_RGB_PATTERN % tuple(self._rgb) mqtt.publish(self._hass, self._topic["rgb_command_topic"], rgb, self._qos) if ATTR_BRIGHTNESS in kwargs and \ self._topic["brightness_command_topic"] is not None: self._brightness = kwargs[ATTR_BRIGHTNESS] mqtt.publish(self._hass, self._topic["brightness_command_topic"], self._brightness, self._qos) mqtt.publish(self._hass, self._topic["command_topic"], self._payload["on"], self._qos) if self._optimistic: # optimistically assume that switch has changed state self._state = True self.update_ha_state()
def stop_cover(self, **kwargs): """Stop the device.""" mqtt.publish(self.hass, self._command_topic, self._payload_stop, self._qos, self._retain)
def turn_off(self) -> None: """Turn off the entity.""" mqtt.publish(self._hass, self._topic[CONF_COMMAND_TOPIC], self._payload[STATE_OFF], self._qos, self._retain)