示例#1
0
文件: mqtt.py 项目: bdfoster/blumate
 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()
示例#2
0
文件: mqtt.py 项目: lumavp/blumate
 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()
示例#3
0
文件: mqtt.py 项目: lumavp/blumate
 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()
示例#4
0
文件: mqtt.py 项目: bdfoster/blumate
 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()
示例#5
0
文件: mqtt.py 项目: bdfoster/blumate
 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()
示例#6
0
 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()
示例#7
0
文件: mqtt.py 项目: lumavp/blumate
 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()
示例#8
0
    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])
示例#9
0
    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])
示例#10
0
文件: mqtt.py 项目: lumavp/blumate
    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()
示例#11
0
文件: mqtt.py 项目: bdfoster/blumate
 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)
示例#12
0
文件: mqtt.py 项目: lumavp/blumate
 def stop(self, **kwargs):
     """Stop the device."""
     mqtt.publish(self.hass, self._command_topic, self._payload_stop,
                  self._qos)
示例#13
0
文件: mqtt.py 项目: lumavp/blumate
 def move_down(self, **kwargs):
     """Move the roller shutter down."""
     mqtt.publish(self.hass, self._command_topic, self._payload_down,
                  self._qos)
示例#14
0
文件: mqtt.py 项目: lumavp/blumate
 def move_up(self, **kwargs):
     """Move the roller shutter up."""
     mqtt.publish(self.hass, self._command_topic, self._payload_up,
                  self._qos)
示例#15
0
 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)
示例#16
0
文件: mqtt.py 项目: bdfoster/blumate
 def stop(self, **kwargs):
     """Stop the device."""
     mqtt.publish(self.hass, self._command_topic, self._payload_stop,
                  self._qos)
示例#17
0
文件: mqtt.py 项目: bdfoster/blumate
 def move_down(self, **kwargs):
     """Move the roller shutter down."""
     mqtt.publish(self.hass, self._command_topic, self._payload_down,
                  self._qos)
示例#18
0
文件: mqtt.py 项目: bdfoster/blumate
 def move_up(self, **kwargs):
     """Move the roller shutter up."""
     mqtt.publish(self.hass, self._command_topic, self._payload_up,
                  self._qos)
示例#19
0
 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)
示例#20
0
文件: mqtt.py 项目: bdfoster/blumate
 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)
示例#21
0
 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)
示例#22
0
文件: mqtt.py 项目: bdfoster/blumate
 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)