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 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 turn_off(self, **kwargs): """Turn the device off.""" mqtt.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.update_ha_state()
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 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.pool.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 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, self._retain) 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, self._retain) 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, 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 alarm_disarm(self, code=None): """Send disarm command.""" if not self._validate_code(code, 'disarming'): return mqtt.publish(self.hass, self._command_topic, self._payload_disarm, self._qos)
def stop(self, **kwargs): """Stop the device.""" mqtt.publish(self.hass, self._command_topic, self._payload_stop, self._qos)
def move_down(self, **kwargs): """Move the roller shutter down.""" mqtt.publish(self.hass, self._command_topic, self._payload_down, self._qos)
def move_up(self, **kwargs): """Move the roller shutter up.""" mqtt.publish(self.hass, self._command_topic, self._payload_up, self._qos)
def alarm_arm_home(self, code=None): """Send arm home command.""" if not self._validate_code(code, 'arming home'): return mqtt.publish(self.hass, self._command_topic, self._payload_arm_home, self._qos)
def alarm_arm_away(self, code=None): """Send arm away command.""" if not self._validate_code(code, 'arming away'): return mqtt.publish(self.hass, self._command_topic, self._payload_arm_away, self._qos)