当前位置: 首页>>代码示例>>Python>>正文


Python common.fire_mqtt_message函数代码示例

本文整理汇总了Python中tests.common.fire_mqtt_message函数的典型用法代码示例。如果您正苦于以下问题:Python fire_mqtt_message函数的具体用法?Python fire_mqtt_message怎么用?Python fire_mqtt_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fire_mqtt_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_default_availability_payload

    def test_default_availability_payload(self):
        """Test availability by default payload with defined topic."""
        self.assertTrue(setup_component(self.hass, light.DOMAIN, {
            light.DOMAIN: {
                'platform': 'mqtt_template',
                'name': 'test',
                'command_topic': 'test_light_rgb/set',
                'command_on_template': 'on,{{ transition }}',
                'command_off_template': 'off,{{ transition|d }}',
                'availability_topic': 'availability-topic'
            }
        }))

        state = self.hass.states.get('light.test')
        self.assertEqual(STATE_UNAVAILABLE, state.state)

        fire_mqtt_message(self.hass, 'availability-topic', 'online')
        self.hass.block_till_done()

        state = self.hass.states.get('light.test')
        self.assertNotEqual(STATE_UNAVAILABLE, state.state)

        fire_mqtt_message(self.hass, 'availability-topic', 'offline')
        self.hass.block_till_done()

        state = self.hass.states.get('light.test')
        self.assertEqual(STATE_UNAVAILABLE, state.state)
开发者ID:tmcarr,项目名称:home-assistant,代码行数:27,代码来源:test_mqtt_template.py

示例2: test_tilt_via_topic

    def test_tilt_via_topic(self):
        """Test tilt by updating status via MQTT."""
        self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
            cover.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'state-topic',
                'command_topic': 'command-topic',
                'qos': 0,
                'payload_open': 'OPEN',
                'payload_close': 'CLOSE',
                'payload_stop': 'STOP',
                'tilt_command_topic': 'tilt-command-topic',
                'tilt_status_topic': 'tilt-status-topic',
                'tilt_opened_value': 400,
                'tilt_closed_value': 125
            }
        }))

        fire_mqtt_message(self.hass, 'tilt-status-topic', '0')
        self.hass.block_till_done()

        current_cover_tilt_position = self.hass.states.get(
            'cover.test').attributes['current_tilt_position']
        self.assertEqual(0, current_cover_tilt_position)

        fire_mqtt_message(self.hass, 'tilt-status-topic', '50')
        self.hass.block_till_done()

        current_cover_tilt_position = self.hass.states.get(
            'cover.test').attributes['current_tilt_position']
        self.assertEqual(50, current_cover_tilt_position)
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:32,代码来源:test_mqtt.py

示例3: test_availability_by_custom_payload

    def test_availability_by_custom_payload(self):
        """Test availability by custom payload with defined topic."""
        self.assertTrue(setup_component(self.hass, cover.DOMAIN, {
            cover.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'state-topic',
                'command_topic': 'command-topic',
                'availability_topic': 'availability-topic',
                'payload_available': 'good',
                'payload_not_available': 'nogood'
            }
        }))

        state = self.hass.states.get('cover.test')
        self.assertEqual(STATE_UNAVAILABLE, state.state)

        fire_mqtt_message(self.hass, 'availability-topic', 'good')
        self.hass.block_till_done()

        state = self.hass.states.get('cover.test')
        self.assertNotEqual(STATE_UNAVAILABLE, state.state)

        fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
        self.hass.block_till_done()

        state = self.hass.states.get('cover.test')
        self.assertEqual(STATE_UNAVAILABLE, state.state)
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:28,代码来源:test_mqtt.py

示例4: test_default_availability_payload

    def test_default_availability_payload(self):
        """Test availability by default payload with defined topic."""
        self.assertTrue(setup_component(self.hass, lock.DOMAIN, {
            lock.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'state-topic',
                'command_topic': 'command-topic',
                'payload_lock': 'LOCK',
                'payload_unlock': 'UNLOCK',
                'availability_topic': 'availability-topic'
            }
        }))

        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_UNAVAILABLE, state.state)

        fire_mqtt_message(self.hass, 'availability-topic', 'online')
        self.hass.block_till_done()

        state = self.hass.states.get('lock.test')
        self.assertNotEqual(STATE_UNAVAILABLE, state.state)

        fire_mqtt_message(self.hass, 'availability-topic', 'offline')
        self.hass.block_till_done()

        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_UNAVAILABLE, state.state)
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:28,代码来源:test_mqtt.py

示例5: test_controlling_state_via_topic_and_json_message

    def test_controlling_state_via_topic_and_json_message(self):
        """Test the controlling state via topic and JSON message."""
        assert setup_component(self.hass, lock.DOMAIN, {
            lock.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'state-topic',
                'command_topic': 'command-topic',
                'payload_lock': 'LOCK',
                'payload_unlock': 'UNLOCK',
                'value_template': '{{ value_json.val }}'
            }
        })

        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_UNLOCKED, state.state)

        fire_mqtt_message(self.hass, 'state-topic', '{"val":"LOCK"}')
        self.hass.block_till_done()

        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_LOCKED, state.state)

        fire_mqtt_message(self.hass, 'state-topic', '{"val":"UNLOCK"}')
        self.hass.block_till_done()

        state = self.hass.states.get('lock.test')
        self.assertEqual(STATE_UNLOCKED, state.state)
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:28,代码来源:test_mqtt.py

示例6: test_set_target_temperature_pessimistic

    def test_set_target_temperature_pessimistic(self):
        """Test setting the target temperature."""
        config = copy.deepcopy(DEFAULT_CONFIG)
        config['climate']['temperature_state_topic'] = 'temperature-state'
        assert setup_component(self.hass, climate.DOMAIN, config)

        state = self.hass.states.get(ENTITY_CLIMATE)
        assert state.attributes.get('temperature') is None
        common.set_operation_mode(self.hass, 'heat', ENTITY_CLIMATE)
        self.hass.block_till_done()
        common.set_temperature(self.hass, temperature=47,
                               entity_id=ENTITY_CLIMATE)
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert state.attributes.get('temperature') is None

        fire_mqtt_message(self.hass, 'temperature-state', '1701')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert 1701 == state.attributes.get('temperature')

        fire_mqtt_message(self.hass, 'temperature-state', 'not a number')
        self.hass.block_till_done()
        state = self.hass.states.get(ENTITY_CLIMATE)
        assert 1701 == state.attributes.get('temperature')
开发者ID:ManHammer,项目名称:home-assistant,代码行数:25,代码来源:test_mqtt.py

示例7: test_no_color_brightness_color_temp_white_val_if_no_topics

    def test_no_color_brightness_color_temp_white_val_if_no_topics(self):
        """Test for no RGB, brightness, color temp, effect, white val or XY."""
        assert setup_component(self.hass, light.DOMAIN, {
            light.DOMAIN: {
                'platform': 'mqtt_json',
                'name': 'test',
                'state_topic': 'test_light_rgb',
                'command_topic': 'test_light_rgb/set',
            }
        })

        state = self.hass.states.get('light.test')
        self.assertEqual(STATE_OFF, state.state)
        self.assertEqual(40, state.attributes.get(ATTR_SUPPORTED_FEATURES))
        self.assertIsNone(state.attributes.get('rgb_color'))
        self.assertIsNone(state.attributes.get('brightness'))
        self.assertIsNone(state.attributes.get('color_temp'))
        self.assertIsNone(state.attributes.get('effect'))
        self.assertIsNone(state.attributes.get('white_value'))
        self.assertIsNone(state.attributes.get('xy_color'))
        self.assertIsNone(state.attributes.get('hs_color'))

        fire_mqtt_message(self.hass, 'test_light_rgb', '{"state":"ON"}')
        self.hass.block_till_done()

        state = self.hass.states.get('light.test')
        self.assertEqual(STATE_ON, state.state)
        self.assertIsNone(state.attributes.get('rgb_color'))
        self.assertIsNone(state.attributes.get('brightness'))
        self.assertIsNone(state.attributes.get('color_temp'))
        self.assertIsNone(state.attributes.get('effect'))
        self.assertIsNone(state.attributes.get('white_value'))
        self.assertIsNone(state.attributes.get('xy_color'))
        self.assertIsNone(state.attributes.get('hs_color'))
开发者ID:chuchock,项目名称:home-assistant,代码行数:34,代码来源:test_mqtt_json.py

示例8: test_controlling_state_via_topic_and_json_message

    def test_controlling_state_via_topic_and_json_message(self):
        """Test the controlling state via topic and JSON message."""
        with assert_setup_component(1):
            assert setup_component(self.hass, garage_door.DOMAIN, {
                garage_door.DOMAIN: {
                    'platform': 'mqtt',
                    'name': 'test',
                    'state_topic': 'state-topic',
                    'command_topic': 'command-topic',
                    'state_open': 'beer open',
                    'state_closed': 'beer closed',
                    'service_open': 'beer service open',
                    'service_close': 'beer service close',
                    'value_template': '{{ value_json.val }}'
                }
            })

        state = self.hass.states.get('garage_door.test')
        self.assertEqual(STATE_CLOSED, state.state)

        fire_mqtt_message(self.hass, 'state-topic', '{"val":"beer open"}')
        self.hass.block_till_done()

        state = self.hass.states.get('garage_door.test')
        self.assertEqual(STATE_OPEN, state.state)

        fire_mqtt_message(self.hass, 'state-topic', '{"val":"beer closed"}')
        self.hass.block_till_done()

        state = self.hass.states.get('garage_door.test')
        self.assertEqual(STATE_CLOSED, state.state)
开发者ID:krzynio,项目名称:home-assistant,代码行数:31,代码来源:test_mqtt.py

示例9: test_if_fires_on_topic_match

    def test_if_fires_on_topic_match(self):
        """Test if message is fired on topic match."""
        assert setup_component(self.hass, automation.DOMAIN, {
            automation.DOMAIN: {
                'trigger': {
                    'platform': 'mqtt',
                    'topic': 'test-topic'
                },
                'action': {
                    'service': 'test.automation',
                    'data_template': {
                        'some': '{{ trigger.platform }} - {{ trigger.topic }}'
                                ' - {{ trigger.payload }}'
                    },
                }
            }
        })

        fire_mqtt_message(self.hass, 'test-topic', 'test_payload')
        self.hass.block_till_done()
        self.assertEqual(1, len(self.calls))
        self.assertEqual('mqtt - test-topic - test_payload',
                         self.calls[0].data['some'])

        automation.turn_off(self.hass)
        self.hass.block_till_done()
        fire_mqtt_message(self.hass, 'test-topic', 'test_payload')
        self.hass.block_till_done()
        self.assertEqual(1, len(self.calls))
开发者ID:GadgetReactor,项目名称:home-assistant,代码行数:29,代码来源:test_mqtt.py

示例10: test_no_color_brightness_color_temp_white_xy_if_no_topics

    def test_no_color_brightness_color_temp_white_xy_if_no_topics(self): \
            # pylint: disable=invalid-name
        """Test if there is no color and brightness if no topic."""
        with assert_setup_component(1, light.DOMAIN):
            assert setup_component(self.hass, light.DOMAIN, {
                light.DOMAIN: {
                    'platform': 'mqtt',
                    'name': 'test',
                    'state_topic': 'test_light_rgb/status',
                    'command_topic': 'test_light_rgb/set',
                }
            })

        state = self.hass.states.get('light.test')
        self.assertEqual(STATE_OFF, state.state)
        self.assertIsNone(state.attributes.get('rgb_color'))
        self.assertIsNone(state.attributes.get('brightness'))
        self.assertIsNone(state.attributes.get('color_temp'))
        self.assertIsNone(state.attributes.get('white_value'))
        self.assertIsNone(state.attributes.get('xy_color'))

        fire_mqtt_message(self.hass, 'test_light_rgb/status', 'ON')
        self.hass.block_till_done()

        state = self.hass.states.get('light.test')
        self.assertEqual(STATE_ON, state.state)
        self.assertIsNone(state.attributes.get('rgb_color'))
        self.assertIsNone(state.attributes.get('brightness'))
        self.assertIsNone(state.attributes.get('color_temp'))
        self.assertIsNone(state.attributes.get('white_value'))
        self.assertIsNone(state.attributes.get('xy_color'))
开发者ID:Landrash,项目名称:home-assistant,代码行数:31,代码来源:test_mqtt.py

示例11: test_setting_sensor_value_via_mqtt_message

    def test_setting_sensor_value_via_mqtt_message(self):
        """Test the setting of the value via MQTT."""
        self.hass.config.components = ['mqtt']
        assert _setup_component(self.hass, binary_sensor.DOMAIN, {
            binary_sensor.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'test-topic',
                'payload_on': 'ON',
                'payload_off': 'OFF',
            }
        })

        state = self.hass.states.get('binary_sensor.test')
        self.assertEqual(STATE_OFF, state.state)

        fire_mqtt_message(self.hass, 'test-topic', 'ON')
        self.hass.block_till_done()
        state = self.hass.states.get('binary_sensor.test')
        self.assertEqual(STATE_ON, state.state)

        fire_mqtt_message(self.hass, 'test-topic', 'OFF')
        self.hass.block_till_done()
        state = self.hass.states.get('binary_sensor.test')
        self.assertEqual(STATE_OFF, state.state)
开发者ID:Bart274,项目名称:home-assistant,代码行数:25,代码来源:test_mqtt.py

示例12: test_custom_state_payload

    def test_custom_state_payload(self):
        """Test the state payload."""
        assert setup_component(self.hass, switch.DOMAIN, {
            switch.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'state-topic',
                'command_topic': 'command-topic',
                'payload_on': 1,
                'payload_off': 0,
                'state_on': "HIGH",
                'state_off': "LOW",
            }
        })

        state = self.hass.states.get('switch.test')
        self.assertEqual(STATE_OFF, state.state)
        self.assertFalse(state.attributes.get(ATTR_ASSUMED_STATE))

        fire_mqtt_message(self.hass, 'state-topic', 'HIGH')
        self.hass.block_till_done()

        state = self.hass.states.get('switch.test')
        self.assertEqual(STATE_ON, state.state)

        fire_mqtt_message(self.hass, 'state-topic', 'LOW')
        self.hass.block_till_done()

        state = self.hass.states.get('switch.test')
        self.assertEqual(STATE_OFF, state.state)
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:30,代码来源:test_mqtt.py

示例13: test_custom_availability_payload

    def test_custom_availability_payload(self):
        """Test availability by custom payload with defined topic."""
        self.assertTrue(setup_component(self.hass, light.DOMAIN, {
            light.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'command_topic': 'test_light/set',
                'brightness_command_topic': 'test_light/bright',
                'rgb_command_topic': "test_light/rgb",
                'availability_topic': 'availability-topic',
                'payload_available': 'good',
                'payload_not_available': 'nogood'
            }
        }))

        state = self.hass.states.get('light.test')
        self.assertEqual(STATE_UNAVAILABLE, state.state)

        fire_mqtt_message(self.hass, 'availability-topic', 'good')
        self.hass.block_till_done()

        state = self.hass.states.get('light.test')
        self.assertNotEqual(STATE_UNAVAILABLE, state.state)

        fire_mqtt_message(self.hass, 'availability-topic', 'nogood')
        self.hass.block_till_done()

        state = self.hass.states.get('light.test')
        self.assertEqual(STATE_UNAVAILABLE, state.state)
开发者ID:W00D00,项目名称:home-assistant,代码行数:29,代码来源:test_mqtt.py

示例14: test_disarm_pending_via_command_topic

    def test_disarm_pending_via_command_topic(self):
        """Test disarming pending alarm via command topic."""
        assert setup_component(self.hass, alarm_control_panel.DOMAIN, {
            alarm_control_panel.DOMAIN: {
                'platform': 'manual_mqtt',
                'name': 'test',
                'pending_time': 1,
                'state_topic': 'alarm/state',
                'command_topic': 'alarm/command',
                'payload_disarm': 'DISARM',
            }
        })

        entity_id = 'alarm_control_panel.test'

        self.assertEqual(STATE_ALARM_DISARMED,
                         self.hass.states.get(entity_id).state)

        alarm_control_panel.alarm_trigger(self.hass)
        self.hass.block_till_done()

        self.assertEqual(STATE_ALARM_PENDING,
                         self.hass.states.get(entity_id).state)

        # Now that we're pending, receive a command to disarm
        fire_mqtt_message(self.hass, 'alarm/command', 'DISARM')
        self.hass.block_till_done()

        self.assertEqual(STATE_ALARM_DISARMED,
                         self.hass.states.get(entity_id).state)
开发者ID:robbiet480,项目名称:home-assistant,代码行数:30,代码来源:test_manual_mqtt.py

示例15: test_controlling_state_via_topic

    def test_controlling_state_via_topic(self):
        """Test the controlling state via topic."""
        with assert_setup_component(1):
            assert setup_component(self.hass, garage_door.DOMAIN, {
                garage_door.DOMAIN: {
                    'platform': 'mqtt',
                    'name': 'test',
                    'state_topic': 'state-topic',
                    'command_topic': 'command-topic',
                    'state_open': 1,
                    'state_closed': 0,
                    'service_open': 1,
                    'service_close': 0
                }
            })

        state = self.hass.states.get('garage_door.test')
        self.assertEqual(STATE_CLOSED, state.state)
        self.assertIsNone(state.attributes.get(ATTR_ASSUMED_STATE))

        fire_mqtt_message(self.hass, 'state-topic', '1')
        self.hass.block_till_done()

        state = self.hass.states.get('garage_door.test')
        self.assertEqual(STATE_OPEN, state.state)

        fire_mqtt_message(self.hass, 'state-topic', '0')
        self.hass.block_till_done()

        state = self.hass.states.get('garage_door.test')
        self.assertEqual(STATE_CLOSED, state.state)
开发者ID:krzynio,项目名称:home-assistant,代码行数:31,代码来源:test_mqtt.py


注:本文中的tests.common.fire_mqtt_message函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。