async def async_set_cover_position(self, **kwargs): """Move the cover to a specific position.""" set_position_template = self._config.get(CONF_SET_POSITION_TEMPLATE) if ATTR_POSITION in kwargs: position = kwargs[ATTR_POSITION] percentage_position = position if set_position_template is not None: try: position = set_position_template.async_render( **kwargs) except TemplateError as ex: _LOGGER.error(ex) self._state = None elif (self._config.get(CONF_POSITION_OPEN) != 100 and self._config.get(CONF_POSITION_CLOSED) != 0): position = self.find_in_range_from_percent( position, COVER_PAYLOAD) mqtt.async_publish(self.hass, self._config.get(CONF_SET_POSITION_TOPIC), position, self._config.get(CONF_QOS), self._config.get(CONF_RETAIN)) if self._optimistic: self._state = percentage_position == \ self._config.get(CONF_POSITION_CLOSED) self._position = percentage_position self.async_schedule_update_ha_state()
async def async_set_speed(self, speed: str) -> None: """Set the speed of the fan. This method is a coroutine. """ if self._topic[CONF_SPEED_COMMAND_TOPIC] is None: return 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 mqtt.async_publish( self.hass, self._topic[CONF_SPEED_COMMAND_TOPIC], mqtt_payload, self._config.get(CONF_QOS), self._config.get(CONF_RETAIN)) if self._optimistic_speed: self._speed = speed self.async_write_ha_state()
def async_turn_off(self) -> None: """Turn off the entity. This method is a coroutine. """ mqtt.async_publish( self.hass, self._topic[CONF_COMMAND_TOPIC], self._payload[STATE_OFF], self._qos, self._retain)
def async_open_cover_tilt(self, **kwargs): """Tilt the cover open.""" mqtt.async_publish(self.hass, self._tilt_command_topic, self._tilt_open_position, self._qos, self._retain) if self._tilt_optimistic: self._tilt_value = self._tilt_open_position self.hass.async_add_job(self.async_update_ha_state())
async def async_locate(self, **kwargs): """Locate the vacuum (usually by playing a song).""" if self.supported_features & SUPPORT_LOCATE == 0: return None mqtt.async_publish(self.hass, self._command_topic, self._config[CONF_PAYLOAD_LOCATE], self._config[CONF_QOS], self._config[CONF_RETAIN])
async def async_clean_spot(self, **kwargs): """Perform a spot clean-up.""" if self.supported_features & SUPPORT_CLEAN_SPOT == 0: return None mqtt.async_publish(self.hass, self._command_topic, self._config[CONF_PAYLOAD_CLEAN_SPOT], self._config[CONF_QOS], self._config[CONF_RETAIN])
async def async_return_to_base(self, **kwargs): """Tell the vacuum to return to its dock.""" if self.supported_features & SUPPORT_RETURN_HOME == 0: return None mqtt.async_publish(self.hass, self._command_topic, self._config[CONF_PAYLOAD_RETURN_TO_BASE], self._config[CONF_QOS], self._config[CONF_RETAIN])
async def async_stop(self, **kwargs): """Stop the vacuum.""" if self.supported_features & SUPPORT_STOP == 0: return None mqtt.async_publish(self.hass, self._command_topic, self._config[CONF_PAYLOAD_STOP], self._config[CONF_QOS], self._config[CONF_RETAIN])
async def async_pause(self): """Pause the vacuum.""" if self.supported_features & SUPPORT_PAUSE == 0: return None mqtt.async_publish(self.hass, self._command_topic, self._config[CONF_PAYLOAD_PAUSE], self._config[CONF_QOS], self._config[CONF_RETAIN])
async def async_start(self): """Start the vacuum.""" if self.supported_features & SUPPORT_START == 0: return None mqtt.async_publish(self.hass, self._command_topic, self._config[CONF_PAYLOAD_START], self._config[CONF_QOS], self._config[CONF_RETAIN])
def async_stop_cover(self, **kwargs): """Stop the device. This method is a coroutine. """ mqtt.async_publish( self.hass, self._command_topic, self._payload_stop, self._qos, self._retain)
def async_close_cover_tilt(self, **kwargs): """Tilt the cover closed.""" mqtt.async_publish(self.hass, self._tilt_command_topic, self._tilt_closed_position, self._qos, self._retain) if self._tilt_optimistic: self._tilt_value = self._tilt_closed_position self.async_schedule_update_ha_state()
async def async_set_fan_speed(self, fan_speed, **kwargs): """Set fan speed.""" if ((self.supported_features & SUPPORT_FAN_SPEED == 0) or (fan_speed not in self._fan_speed_list)): return None mqtt.async_publish(self.hass, self._set_fan_speed_topic, fan_speed, self._config[CONF_QOS], self._config[CONF_RETAIN])
def async_turn_on(self, **kwargs): """Turn the entity on. This method is a coroutine. """ values = {'state': True} if self._optimistic: self._state = True if ATTR_BRIGHTNESS in kwargs: values['brightness'] = int(kwargs[ATTR_BRIGHTNESS]) if self._optimistic: self._brightness = kwargs[ATTR_BRIGHTNESS] if ATTR_COLOR_TEMP in kwargs: values['color_temp'] = int(kwargs[ATTR_COLOR_TEMP]) if self._optimistic: self._color_temp = kwargs[ATTR_COLOR_TEMP] if ATTR_HS_COLOR in kwargs: hs_color = kwargs[ATTR_HS_COLOR] brightness = kwargs.get( ATTR_BRIGHTNESS, self._brightness if self._brightness else 255) rgb = color_util.color_hsv_to_RGB( hs_color[0], hs_color[1], brightness / 255 * 100) values['red'] = rgb[0] values['green'] = rgb[1] values['blue'] = rgb[2] if self._optimistic: self._hs = kwargs[ATTR_HS_COLOR] if ATTR_WHITE_VALUE in kwargs: values['white_value'] = int(kwargs[ATTR_WHITE_VALUE]) if self._optimistic: self._white_value = kwargs[ATTR_WHITE_VALUE] if ATTR_EFFECT in kwargs: values['effect'] = kwargs.get(ATTR_EFFECT) if ATTR_FLASH in kwargs: values['flash'] = kwargs.get(ATTR_FLASH) if ATTR_TRANSITION in kwargs: values['transition'] = int(kwargs[ATTR_TRANSITION]) mqtt.async_publish( self.hass, self._topics[CONF_COMMAND_TOPIC], self._templates[CONF_COMMAND_ON_TEMPLATE].async_render(**values), self._qos, self._retain ) if self._optimistic: self.async_schedule_update_ha_state()
async def async_stop_cover(self, **kwargs): """Stop the device. This method is a coroutine. """ mqtt.async_publish( self.hass, self._config.get(CONF_COMMAND_TOPIC), self._config.get(CONF_PAYLOAD_STOP), self._config.get(CONF_QOS), self._config.get(CONF_RETAIN))
def async_stop(self, **kwargs): """Stop the vacuum.""" if self.supported_features & SUPPORT_STOP == 0: return mqtt.async_publish(self.hass, self._command_topic, self._payload_stop, self._qos, self._retain) self._status = 'Stopping the current task' self.async_schedule_update_ha_state()
async def async_send_command(self, command, params=None, **kwargs): """Send a command to a vacuum cleaner.""" if self.supported_features & SUPPORT_SEND_COMMAND == 0: return mqtt.async_publish(self.hass, self._send_command_topic, command, self._qos, self._retain) self._status = "Sending command {}...".format(command) self.async_schedule_update_ha_state()
def async_clean_spot(self, **kwargs): """Perform a spot clean-up.""" if self.supported_features & SUPPORT_CLEAN_SPOT == 0: return mqtt.async_publish(self.hass, self._command_topic, self._payload_clean_spot, self._qos, self._retain) self._status = "Cleaning spot" self.async_schedule_update_ha_state()
def async_locate(self, **kwargs): """Locate the vacuum (usually by playing a song).""" if self.supported_features & SUPPORT_LOCATE == 0: return mqtt.async_publish(self.hass, self._command_topic, self._payload_locate, self._qos, self._retain) self._status = "Hi, I'm over here!" self.async_schedule_update_ha_state()
def async_alarm_arm_away(self, code=None): """Send arm away command. This method is a coroutine. """ if not self._validate_code(code, 'arming away'): return mqtt.async_publish( self.hass, self._command_topic, self._payload_arm_away, self._qos)
def async_start_pause(self, **kwargs): """Start, pause or resume the cleaning task.""" if self.supported_features & SUPPORT_PAUSE == 0: return mqtt.async_publish(self.hass, self._command_topic, self._payload_start_pause, self._qos, self._retain) self._status = 'Pausing/Resuming cleaning...' self.async_schedule_update_ha_state()
def async_turn_off(self, **kwargs): """Turn the vacuum off.""" if self.supported_features & SUPPORT_TURN_OFF == 0: return mqtt.async_publish(self.hass, self._command_topic, self._payload_turn_off, self._qos, self._retain) self._status = 'Turning Off' self.async_schedule_update_ha_state()
def async_turn_aux_heat_off(self): """Turn auxiliary heater off.""" if self._topic[CONF_AUX_COMMAND_TOPIC] is not None: mqtt.async_publish(self.hass, self._topic[CONF_AUX_COMMAND_TOPIC], self._payload_off, self._qos, self._retain) if self._topic[CONF_AUX_STATE_TOPIC] is None: self._aux = False self.async_schedule_update_ha_state()
async def async_turn_off(self, **kwargs) -> None: """Turn off the entity. This method is a coroutine. """ mqtt.async_publish( self.hass, self._topic[CONF_COMMAND_TOPIC], self._payload[STATE_OFF], self._config.get(CONF_QOS), self._config.get(CONF_RETAIN))
async def snips_say(call): """Send a Snips notification message.""" notification = {'siteId': call.data.get(ATTR_SITE_ID, 'default'), 'customData': call.data.get(ATTR_CUSTOM_DATA, ''), 'init': {'type': 'notification', 'text': call.data.get(ATTR_TEXT)}} mqtt.async_publish(hass, 'hermes/dialogueManager/startSession', json.dumps(notification)) return
async def message_received(msg): """Handle new messages on MQTT.""" _LOGGER.debug("New intent: %s", msg.payload) try: request = json.loads(msg.payload) except TypeError: _LOGGER.error('Received invalid JSON: %s', msg.payload) return if (request['intent']['confidenceScore'] < config[DOMAIN].get(CONF_PROBABILITY)): _LOGGER.warning("Intent below probaility threshold %s < %s", request['intent']['confidenceScore'], config[DOMAIN].get(CONF_PROBABILITY)) return try: request = INTENT_SCHEMA(request) except vol.Invalid as err: _LOGGER.error('Intent has invalid schema: %s. %s', err, request) return if request['intent']['intentName'].startswith('user_'): intent_type = request['intent']['intentName'].split('__')[-1] else: intent_type = request['intent']['intentName'].split(':')[-1] snips_response = None slots = {} for slot in request.get('slots', []): slots[slot['slotName']] = {'value': resolve_slot_values(slot)} slots['{}_raw'.format(slot['slotName'])] = { 'value': slot['rawValue']} slots['site_id'] = {'value': request.get('siteId')} slots['session_id'] = {'value': request.get('sessionId')} slots['confidenceScore'] = { 'value': request['intent']['confidenceScore'] } try: intent_response = await intent.async_handle( hass, DOMAIN, intent_type, slots, request['input']) if 'plain' in intent_response.speech: snips_response = intent_response.speech['plain']['speech'] except intent.UnknownIntent: _LOGGER.warning("Received unknown intent %s", request['intent']['intentName']) except intent.IntentError: _LOGGER.exception("Error while handling intent: %s.", intent_type) if snips_response: notification = {'sessionId': request.get('sessionId', 'default'), 'text': snips_response} _LOGGER.debug("send_response %s", json.dumps(notification)) mqtt.async_publish(hass, 'hermes/dialogueManager/endSession', json.dumps(notification))
def async_alarm_disarm(self, code=None): """Send disarm command. This method is a coroutine. """ if not self._validate_code(code, 'disarming'): return mqtt.async_publish( self.hass, self._command_topic, self._payload_disarm, self._qos)
async def async_alarm_arm_home(self, code=None): """Send arm home command. This method is a coroutine. """ if not self._validate_code(code, 'arming home'): return mqtt.async_publish( self.hass, self._command_topic, self._payload_arm_home, self._qos, self._retain)
def async_set_hold_mode(self, hold_mode): """Update hold mode on.""" if self._topic[CONF_HOLD_COMMAND_TOPIC] is not None: mqtt.async_publish(self.hass, self._topic[CONF_HOLD_COMMAND_TOPIC], hold_mode, self._qos, self._retain) if self._topic[CONF_HOLD_STATE_TOPIC] is None: self._hold = hold_mode self.async_schedule_update_ha_state()
def async_turn_away_mode_off(self): """Turn away mode off.""" if self._topic[CONF_AWAY_MODE_COMMAND_TOPIC] is not None: mqtt.async_publish(self.hass, self._topic[CONF_AWAY_MODE_COMMAND_TOPIC], self._payload_off, self._qos, self._retain) if self._topic[CONF_AWAY_MODE_STATE_TOPIC] is None: self._away = False self.async_schedule_update_ha_state()
async def async_alarm_arm_away(self, code=None): """Send arm away command. This method is a coroutine. """ if not self._validate_code(code, 'arming away'): return mqtt.async_publish( self.hass, self._config.get(CONF_COMMAND_TOPIC), self._config.get(CONF_PAYLOAD_ARM_AWAY), self._config.get(CONF_QOS), self._config.get(CONF_RETAIN))
async def async_close_cover(self, **kwargs): """Move the cover down. This method is a coroutine. """ mqtt.async_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.async_schedule_update_ha_state()
async def async_turn_away_mode_off(self): """Turn away mode off.""" if self._topic[CONF_AWAY_MODE_COMMAND_TOPIC] is not None: mqtt.async_publish(self.hass, self._topic[CONF_AWAY_MODE_COMMAND_TOPIC], self._config.get(CONF_PAYLOAD_OFF), self._config.get(CONF_QOS), self._config.get(CONF_RETAIN)) if self._topic[CONF_AWAY_MODE_STATE_TOPIC] is None: self._away = False self.async_write_ha_state()
async def async_set_fan_mode(self, fan_mode): """Set new target temperature.""" if (self._config.get(CONF_SEND_IF_OFF) or self._current_operation != STATE_OFF): mqtt.async_publish(self.hass, self._topic[CONF_FAN_MODE_COMMAND_TOPIC], fan_mode, self._config.get(CONF_QOS), self._config.get(CONF_RETAIN)) if self._topic[CONF_FAN_MODE_STATE_TOPIC] is None: self._current_fan_mode = fan_mode self.async_write_ha_state()
async def async_set_swing_mode(self, swing_mode): """Set new swing mode.""" if (self._config.get(CONF_SEND_IF_OFF) or self._current_operation != STATE_OFF): mqtt.async_publish(self.hass, self._topic[CONF_SWING_MODE_COMMAND_TOPIC], swing_mode, self._config.get(CONF_QOS), self._config.get(CONF_RETAIN)) if self._topic[CONF_SWING_MODE_STATE_TOPIC] is None: self._current_swing_mode = swing_mode self.async_write_ha_state()
async def async_stop_cover(self, **kwargs): """Stop the device. This method is a coroutine. """ mqtt.async_publish( self.hass, self._config.get(CONF_COMMAND_TOPIC), self._config[CONF_PAYLOAD_STOP], self._config[CONF_QOS], self._config[CONF_RETAIN], )
def _publish(self, code, action): """Publish via mqtt.""" command_template = self._config[CONF_COMMAND_TEMPLATE] values = {"action": action, "code": code} payload = command_template.async_render(**values) mqtt.async_publish( self.hass, self._config[CONF_COMMAND_TOPIC], payload, self._config[CONF_QOS], self._config[CONF_RETAIN], )
async def async_turn_off(self, **kwargs): """Turn the device off. This method is a coroutine. """ mqtt.async_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.async_schedule_update_ha_state()
def async_turn_off(self, **kwargs): """Turn the device off. This method is a coroutine. """ mqtt.async_publish( self.hass, self._command_topic, self._payload_off, self._qos, self._retain) if self._optimistic: # Optimistically assume that switch has changed state. self._state = False self.hass.async_add_job(self.async_update_ha_state())
async def async_activate(self, **kwargs): """Activate the scene. This method is a coroutine. """ mqtt.async_publish( self.hass, self._config[CONF_COMMAND_TOPIC], self._config[CONF_PAYLOAD_ON], self._config[CONF_QOS], self._config[CONF_RETAIN], )
async def async_unlock(self, **kwargs): """Unlock the device. This method is a coroutine. """ mqtt.async_publish(self.hass, self._config[CONF_COMMAND_TOPIC], self._config[CONF_PAYLOAD_UNLOCK], self._config[CONF_QOS], self._config[CONF_RETAIN]) if self._optimistic: # Optimistically assume that the lock has changed state. self._state = False self.async_write_ha_state()
async def async_turn_on(self, **kwargs): """Turn the device on. This method is a coroutine. """ mqtt.async_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.async_schedule_update_ha_state()
async def async_send_command(self, command, params=None, **kwargs): """Send a command to a vacuum cleaner.""" if self.supported_features & SUPPORT_SEND_COMMAND == 0: return None if params: message = {"command": command} message.update(params) message = json.dumps(message) else: message = command mqtt.async_publish(self.hass, self._send_command_topic, message, self._config[CONF_QOS], self._config[CONF_RETAIN])
async def async_set_cover_tilt_position(self, **kwargs): """Move the cover tilt to a specific position.""" if ATTR_TILT_POSITION not in kwargs: return position = float(kwargs[ATTR_TILT_POSITION]) # The position needs to be between min and max level = self.find_in_range_from_percent(position) mqtt.async_publish(self.hass, self._tilt_command_topic, level, self._qos, self._retain)
async def async_alarm_disarm(self, code=None): """Send disarm command. This method is a coroutine. """ if not self._validate_code(code, 'disarming'): return mqtt.async_publish( self.hass, self._config.get(CONF_COMMAND_TOPIC), self._config.get(CONF_PAYLOAD_DISARM), self._config.get(CONF_QOS), self._config.get(CONF_RETAIN))
async def async_lock(self, **kwargs): """Lock the device. This method is a coroutine. """ mqtt.async_publish(self.hass, self._config[CONF_COMMAND_TOPIC], self._config[CONF_PAYLOAD_LOCK], self._config[CONF_QOS], self._config[CONF_RETAIN]) if self._optimistic: # Optimistically assume that switch has changed state. self._state = True self.async_schedule_update_ha_state()
def async_open_cover(self, **kwargs): """Move the cover up. This method is a coroutine. """ mqtt.async_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.hass.async_add_job(self.async_update_ha_state())
async def async_set_fan_speed(self, fan_speed, **kwargs): """Set fan speed.""" if ( self.supported_features & SUPPORT_FAN_SPEED == 0 ) or fan_speed not in self._fan_speed_list: return None mqtt.async_publish( self.hass, self._set_fan_speed_topic, fan_speed, self._qos, self._retain ) self._status = f"Setting fan to {fan_speed}..." self.async_write_ha_state()
async def async_set_fan_speed(self, fan_speed, **kwargs): """Set fan speed.""" if (self.supported_features & SUPPORT_FAN_SPEED == 0) or (fan_speed not in self._fan_speed_list): return None mqtt.async_publish( self.hass, self._set_fan_speed_topic, fan_speed, self._config[CONF_QOS], self._config[CONF_RETAIN], )
async def async_alarm_arm_night(self, code=None): """Send arm night command. This method is a coroutine. """ code_required = self._config.get(CONF_CODE_ARM_REQUIRED) if code_required and not self._validate_code(code, 'arming night'): return mqtt.async_publish(self.hass, self._config.get(CONF_COMMAND_TOPIC), self._config.get(CONF_PAYLOAD_ARM_NIGHT), self._config.get(CONF_QOS), self._config.get(CONF_RETAIN))
async def async_turn_away_mode_on(self): """Turn away mode on.""" if self._topic[CONF_AWAY_MODE_COMMAND_TOPIC] is not None: mqtt.async_publish(self.hass, self._topic[CONF_AWAY_MODE_COMMAND_TOPIC], self._config.get(CONF_PAYLOAD_ON), self._config.get(CONF_QOS), self._config.get(CONF_RETAIN)) if self._topic[CONF_AWAY_MODE_STATE_TOPIC] is None: self._away = True self.async_schedule_update_ha_state()
def send_ir(self): """Send the payload to tasmota mqtt topic.""" fan_speed = self.fan_mode # tweak for some ELECTRA_AC devices if HVAC_FAN_MAX_HIGH in self._fan_list and HVAC_FAN_AUTO_MAX in self._fan_list: if self.fan_mode == FAN_HIGH: fan_speed = HVAC_FAN_MAX if self.fan_mode == HVAC_FAN_MAX: fan_speed = HVAC_FAN_AUTO # Set the swing mode - default off swing_h = STATE_OFF swing_v = STATE_OFF if self.swing_mode == SWING_BOTH: swing_h = STATE_AUTO swing_v = STATE_AUTO elif self.swing_mode == SWING_HORIZONTAL: swing_h = STATE_AUTO elif self.swing_mode == SWING_VERTICAL: swing_v = STATE_AUTO # hack for some hisense model: if self._turning_on and self._model_on != DEFAULT_CONF_MODEL: model = self._model_on else: model = self._model # Populate the payload payload_data = { "Vendor": self._vendor, "Model": model, "Mode": self._hvac_mode, "Power": self.power_mode, "Celsius": self._celsius, "Temp": self._target_temp, "FanSpeed": fan_speed, "SwingV": swing_v, "SwingH": swing_h, "Quiet": self._quiet, "Turbo": self._turbo, "Econo": self._econo, "Light": self._light, "Filter": self._filters, "Clean": self._clean, "Beep": self._beep, "Sleep": self._sleep } payload = (json.dumps(payload_data)) # Publish mqtt message mqtt.async_publish(self.hass, self.topic, payload) self._turning_on = False
async def message_received(topic, payload, qos): """Handle new messages on MQTT.""" _LOGGER.debug("New intent: %s", payload) try: request = json.loads(payload) except TypeError: _LOGGER.error('Received invalid JSON: %s', payload) return if (request['intent']['probability'] < config[DOMAIN].get(CONF_PROBABILITY)): _LOGGER.warning("Intent below probaility threshold %s < %s", request['intent']['probability'], config[DOMAIN].get(CONF_PROBABILITY)) return try: request = INTENT_SCHEMA(request) except vol.Invalid as err: _LOGGER.error('Intent has invalid schema: %s. %s', err, request) return if request['intent']['intentName'].startswith('user_'): intent_type = request['intent']['intentName'].split('__')[-1] else: intent_type = request['intent']['intentName'].split(':')[-1] snips_response = None slots = {} for slot in request.get('slots', []): slots[slot['slotName']] = {'value': resolve_slot_values(slot)} try: intent_response = await intent.async_handle( hass, DOMAIN, intent_type, slots, request['input']) if 'plain' in intent_response.speech: snips_response = intent_response.speech['plain']['speech'] except intent.UnknownIntent as err: _LOGGER.warning("Received unknown intent %s", request['intent']['intentName']) except intent.IntentError: _LOGGER.exception("Error while handling intent: %s.", intent_type) if snips_response: notification = { 'sessionId': request.get('sessionId', 'default'), 'text': snips_response } _LOGGER.debug("send_response %s", json.dumps(notification)) mqtt.async_publish(hass, 'hermes/dialogueManager/endSession', json.dumps(notification))
def async_turn_on(self, **kwargs): """Turn the entity on. This method is a coroutine. """ values = {'state': True} if self._optimistic: self._state = True if ATTR_BRIGHTNESS in kwargs: values['brightness'] = int(kwargs[ATTR_BRIGHTNESS]) if self._optimistic: self._brightness = kwargs[ATTR_BRIGHTNESS] if ATTR_COLOR_TEMP in kwargs: values['color_temp'] = int(kwargs[ATTR_COLOR_TEMP]) if self._optimistic: self._color_temp = kwargs[ATTR_COLOR_TEMP] 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] if ATTR_WHITE_VALUE in kwargs: values['white_value'] = int(kwargs[ATTR_WHITE_VALUE]) if self._optimistic: self._white_value = kwargs[ATTR_WHITE_VALUE] if ATTR_EFFECT in kwargs: values['effect'] = kwargs.get(ATTR_EFFECT) if ATTR_FLASH in kwargs: values['flash'] = kwargs.get(ATTR_FLASH) if ATTR_TRANSITION in kwargs: values['transition'] = int(kwargs[ATTR_TRANSITION]) mqtt.async_publish( self.hass, self._topics[CONF_COMMAND_TOPIC], self._templates[CONF_COMMAND_ON_TEMPLATE].async_render(**values), self._qos, self._retain ) if self._optimistic: self.async_schedule_update_ha_state()
async def async_turn_off(self, **kwargs): """Turn the device off. This method is a coroutine. """ mqtt.async_publish( self.hass, self._topic[CONF_COMMAND_TOPIC], self._payload['off'], self._config.get(CONF_QOS), self._config.get(CONF_RETAIN)) if self._optimistic: # Optimistically assume that the light has changed state. self._state = False self.async_schedule_update_ha_state()
async def async_close_cover_tilt(self, **kwargs): """Tilt the cover closed.""" mqtt.async_publish( self.hass, self._config.get(CONF_TILT_COMMAND_TOPIC), self._config[CONF_TILT_CLOSED_POSITION], self._config[CONF_QOS], self._config[CONF_RETAIN], ) if self._tilt_optimistic: self._tilt_value = self.find_percentage_in_range( float(self._config[CONF_TILT_CLOSED_POSITION])) self.async_write_ha_state()
async def snips_say(call): """Send a Snips notification message.""" notification = { "siteId": call.data.get(ATTR_SITE_ID, "default"), "customData": call.data.get(ATTR_CUSTOM_DATA, ""), "init": { "type": "notification", "text": call.data.get(ATTR_TEXT) }, } mqtt.async_publish(hass, "hermes/dialogueManager/startSession", json.dumps(notification)) return
async def async_turn_off(self, **kwargs): """Turn the device off. This method is a coroutine. """ mqtt.async_publish(self.hass, self._config.get(CONF_COMMAND_TOPIC), self._config.get(CONF_PAYLOAD_OFF), self._config.get(CONF_QOS), self._config.get(CONF_RETAIN)) if self._optimistic: # Optimistically assume that switch has changed state. self._state = False self.async_write_ha_state()
async def async_turn_on(self, **kwargs): """Turn the device on. This method is a coroutine. """ mqtt.async_publish( self.hass, self._topic+'/set', self._payload['on'], self._qos) # Optimistically assume that switch has changed state. self._state = True self.async_schedule_update_ha_state()
async def snips_say(call): """Send a Snips notification message.""" notification = { 'siteId': call.data.get(ATTR_SITE_ID, 'default'), 'customData': call.data.get(ATTR_CUSTOM_DATA, ''), 'init': { 'type': 'notification', 'text': call.data.get(ATTR_TEXT) } } mqtt.async_publish(hass, 'hermes/dialogueManager/startSession', json.dumps(notification)) return