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


Python common.fire_time_changed函数代码示例

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


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

示例1: test_sunset_trigger

    def test_sunset_trigger(self):
        """Test the sunset trigger."""
        now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
        trigger_time = datetime(2015, 9, 16, 2, tzinfo=dt_util.UTC)

        with patch('homeassistant.util.dt.utcnow',
                   return_value=now):
            setup_component(self.hass, automation.DOMAIN, {
                automation.DOMAIN: {
                    'trigger': {
                        'platform': 'sun',
                        'event': 'sunset',
                    },
                    'action': {
                        'service': 'test.automation',
                    }
                }
            })

        automation.turn_off(self.hass)
        self.hass.block_till_done()

        fire_time_changed(self.hass, trigger_time)
        self.hass.block_till_done()
        self.assertEqual(0, len(self.calls))

        with patch('homeassistant.util.dt.utcnow',
                   return_value=now):
            automation.turn_on(self.hass)
            self.hass.block_till_done()

        fire_time_changed(self.hass, trigger_time)
        self.hass.block_till_done()
        self.assertEqual(1, len(self.calls))
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:34,代码来源:test_sun.py

示例2: test_arm_home_with_pending

    def test_arm_home_with_pending(self):
        """Test arm home method."""
        self.assertTrue(alarm_control_panel.setup(self.hass, {
            'alarm_control_panel': {
                'platform': 'virtual',
                'name': 'test',
                'code': CODE,
                'pending_time': 1
            }}))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_arm_home(self.hass, CODE, entity_id)
        self.hass.pool.block_till_done()

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

        future = dt_util.utcnow() + timedelta(seconds=1)
        with patch(('blumate.components.alarm_control_panel.virtual.'
                    'dt_util.utcnow'), return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.pool.block_till_done()

        self.assertEqual(STATE_ALARM_ARMED_HOME,
                         self.hass.states.get(entity_id).state)
开发者ID:bdfoster,项目名称:blumate,代码行数:29,代码来源:test_virtual.py

示例3: test_if_not_fires_on_entity_change_with_for

    def test_if_not_fires_on_entity_change_with_for(self):
        """Test for not firing on entity change with for."""
        assert setup_component(self.hass, automation.DOMAIN, {
            automation.DOMAIN: {
                'trigger': {
                    'platform': 'numeric_state',
                    'entity_id': 'test.entity',
                    'above': 8,
                    'below': 12,
                    'for': {
                        'seconds': 5
                    },
                },
                'action': {
                    'service': 'test.automation'
                }
            }
        })

        self.hass.states.set('test.entity', 9)
        self.hass.block_till_done()
        self.hass.states.set('test.entity', 15)
        self.hass.block_till_done()
        fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
        self.hass.block_till_done()
        self.assertEqual(0, len(self.calls))
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:26,代码来源:test_numeric_state.py

示例4: test_arm_home_with_pending

    def test_arm_home_with_pending(self):
        """Test arm home method."""
        self.assertTrue(setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'code': CODE,
                'pending_time': 1,
                'disarm_after_trigger': False
            }}))

        entity_id = 'alarm_control_panel.test'

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

        alarm_control_panel.alarm_arm_home(self.hass, CODE, entity_id)
        self.hass.block_till_done()

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

        state = self.hass.states.get(entity_id)
        assert state.attributes['post_pending_state'] == STATE_ALARM_ARMED_HOME

        future = dt_util.utcnow() + timedelta(seconds=1)
        with patch(('homeassistant.components.alarm_control_panel.manual.'
                    'dt_util.utcnow'), return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.block_till_done()

        state = self.hass.states.get(entity_id)
        assert state.state == STATE_ALARM_ARMED_HOME
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:34,代码来源:test_manual.py

示例5: test_trigger_with_specific_trigger_time

    def test_trigger_with_specific_trigger_time(self):
        """Test disarm after trigger."""
        self.assertTrue(setup_component(
            self.hass, alarm_control_panel.DOMAIN,
            {'alarm_control_panel': {
                'platform': 'manual',
                'name': 'test',
                'disarmed': {
                    'trigger_time': 5
                },
                'pending_time': 0,
                'disarm_after_trigger': True
            }}))

        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, entity_id=entity_id)
        self.hass.block_till_done()

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

        future = dt_util.utcnow() + timedelta(seconds=5)
        with patch(('homeassistant.components.alarm_control_panel.manual.'
                    'dt_util.utcnow'), return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.block_till_done()

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

示例6: test_track_same_state_simple_trigger_check_funct

    def test_track_same_state_simple_trigger_check_funct(self):
        """Test track_same_change with trigger and check funct."""
        callback_runs = []
        check_func = []
        period = timedelta(minutes=1)

        @ha.callback
        def callback_run_callback():
            callback_runs.append(1)

        @ha.callback
        def async_check_func(entity, from_s, to_s):
            check_func.append((entity, from_s, to_s))
            return True

        track_same_state(
            self.hass, period, callback_run_callback,
            entity_ids='light.Bowl', async_check_same_func=async_check_func)

        # Adding state to state machine
        self.hass.states.set("light.Bowl", "on")
        self.hass.block_till_done()
        self.assertEqual(0, len(callback_runs))
        self.assertEqual('on', check_func[-1][2].state)
        self.assertEqual('light.bowl', check_func[-1][0])

        # change time to track and see if they trigger
        future = dt_util.utcnow() + period
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()
        self.assertEqual(1, len(callback_runs))
开发者ID:tmcarr,项目名称:home-assistant,代码行数:31,代码来源:test_event.py

示例7: test_arm_night_via_command_topic

    def test_arm_night_via_command_topic(self):
        """Test arming night 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_arm_night': 'ARM_NIGHT',
            }
        })

        entity_id = 'alarm_control_panel.test'

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

        # Fire the arm command via MQTT; ensure state changes to pending
        fire_mqtt_message(self.hass, 'alarm/command', 'ARM_NIGHT')
        self.hass.block_till_done()
        self.assertEqual(STATE_ALARM_PENDING,
                         self.hass.states.get(entity_id).state)

        # Fast-forward a little bit
        future = dt_util.utcnow() + timedelta(seconds=1)
        with patch(('homeassistant.components.alarm_control_panel.manual_mqtt.'
                    'dt_util.utcnow'), return_value=future):
            fire_time_changed(self.hass, future)
            self.hass.block_till_done()

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

示例8: test_stop_covers

    def test_stop_covers(self):
        """Test stop cover function."""
        with assert_setup_component(2, DOMAIN):
            assert setup.setup_component(self.hass, DOMAIN, CONFIG)

        cover.open_cover(self.hass, COVER_GROUP)
        self.hass.block_till_done()
        future = dt_util.utcnow() + timedelta(seconds=1)
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()
        cover.stop_cover(self.hass, COVER_GROUP)
        self.hass.block_till_done()
        future = dt_util.utcnow() + timedelta(seconds=1)
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()

        state = self.hass.states.get(COVER_GROUP)
        self.assertEqual(state.state, STATE_OPEN)
        self.assertEqual(state.attributes.get(ATTR_CURRENT_POSITION), 100)

        self.assertEqual(self.hass.states.get(DEMO_COVER).state, STATE_OPEN)
        self.assertEqual(self.hass.states.get(DEMO_COVER_POS)
                         .attributes.get(ATTR_CURRENT_POSITION), 20)
        self.assertEqual(self.hass.states.get(DEMO_COVER_TILT)
                         .attributes.get(ATTR_CURRENT_POSITION), 80)
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:25,代码来源:test_group.py

示例9: test_delay

    def test_delay(self):
        """Test the delay."""
        event = 'test_event'
        events = []

        def record_event(event):
            """Add recorded event to set."""
            events.append(event)

        self.hass.bus.listen(event, record_event)

        script_obj = script.Script(self.hass, [
            {'event': event},
            {'delay': {'seconds': 5}},
            {'event': event}])

        script_obj.run()

        self.hass.pool.block_till_done()

        assert script_obj.is_running
        assert script_obj.can_cancel
        assert script_obj.last_action == event
        assert len(events) == 1

        future = dt_util.utcnow() + timedelta(seconds=5)
        fire_time_changed(self.hass, future)
        self.hass.pool.block_till_done()

        assert not script_obj.is_running
        assert len(events) == 2
开发者ID:bdfoster,项目名称:blumate,代码行数:31,代码来源:test_script.py

示例10: test_if_not_fires_on_entity_change_with_for

    def test_if_not_fires_on_entity_change_with_for(self):
        """Test for not firing on entity change with for."""
        self.assertTrue(automation.setup(self.hass, {
            automation.DOMAIN: {
                'trigger': {
                    'platform': 'state',
                    'entity_id': 'test.entity',
                    'to': 'world',
                    'for': {
                        'seconds': 5
                    },
                },
                'action': {
                    'service': 'test.automation'
                }
            }
        }))

        self.hass.states.set('test.entity', 'world')
        self.hass.pool.block_till_done()
        self.hass.states.set('test.entity', 'not_world')
        self.hass.pool.block_till_done()
        fire_time_changed(self.hass, dt_util.utcnow() + timedelta(seconds=10))
        self.hass.pool.block_till_done()
        self.assertEqual(0, len(self.calls))
开发者ID:Jamezz,项目名称:home-assistant,代码行数:25,代码来源:test_state.py

示例11: test_delay

    def test_delay(self):
        """Test the delay."""
        event = 'test_event'
        events = []
        context = Context()

        @callback
        def record_event(event):
            """Add recorded event to set."""
            events.append(event)

        self.hass.bus.listen(event, record_event)

        script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
            {'event': event},
            {'delay': {'seconds': 5}},
            {'event': event}]))

        script_obj.run(context=context)
        self.hass.block_till_done()

        assert script_obj.is_running
        assert script_obj.can_cancel
        assert script_obj.last_action == event
        assert len(events) == 1

        future = dt_util.utcnow() + timedelta(seconds=5)
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()

        assert not script_obj.is_running
        assert len(events) == 2
        assert events[0].context is context
        assert events[1].context is context
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:34,代码来源:test_script.py

示例12: test_update_stale

    def test_update_stale(self):
        """Test stalled update."""
        scanner = get_component("device_tracker.test").SCANNER
        scanner.reset()
        scanner.come_home("DEV1")

        register_time = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
        scan_time = datetime(2015, 9, 15, 23, 1, tzinfo=dt_util.UTC)

        with patch("homeassistant.components.device_tracker.dt_util.utcnow", return_value=register_time):
            self.assertTrue(
                setup_component(
                    self.hass,
                    device_tracker.DOMAIN,
                    {device_tracker.DOMAIN: {CONF_PLATFORM: "test", device_tracker.CONF_CONSIDER_HOME: 59}},
                )
            )

        self.assertEqual(STATE_HOME, self.hass.states.get("device_tracker.dev1").state)

        scanner.leave_home("DEV1")

        with patch("homeassistant.components.device_tracker.dt_util.utcnow", return_value=scan_time):
            fire_time_changed(self.hass, scan_time)
            self.hass.block_till_done()

        self.assertEqual(STATE_NOT_HOME, self.hass.states.get("device_tracker.dev1").state)
开发者ID:MartinHjelmare,项目名称:home-assistant,代码行数:27,代码来源:test_init.py

示例13: test_sunrise_trigger

    def test_sunrise_trigger(self):
        """Test the sunrise trigger."""
        self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
            sun.STATE_ATTR_NEXT_RISING: '2015-09-16T14:00:00Z',
        })

        now = datetime(2015, 9, 13, 23, tzinfo=dt_util.UTC)
        trigger_time = datetime(2015, 9, 16, 14, tzinfo=dt_util.UTC)

        with patch('homeassistant.util.dt.utcnow',
                   return_value=now):
            setup_component(self.hass, automation.DOMAIN, {
                automation.DOMAIN: {
                    'trigger': {
                        'platform': 'sun',
                        'event': 'sunrise',
                    },
                    'action': {
                        'service': 'test.automation',
                    }
                }
            })

        fire_time_changed(self.hass, trigger_time)
        self.hass.block_till_done()
        self.assertEqual(1, len(self.calls))
开发者ID:azogue,项目名称:home-assistant,代码行数:26,代码来源:test_sun.py

示例14: test_sunset_trigger_with_offset

    def test_sunset_trigger_with_offset(self):
        """Test the sunset trigger with offset."""
        self.hass.states.set(sun.ENTITY_ID, sun.STATE_ABOVE_HORIZON, {
            sun.STATE_ATTR_NEXT_SETTING: '2015-09-16T02:00:00Z',
        })

        now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
        trigger_time = datetime(2015, 9, 16, 2, 30, tzinfo=dt_util.UTC)

        with patch('homeassistant.util.dt.utcnow',
                   return_value=now):
            setup_component(self.hass, automation.DOMAIN, {
                automation.DOMAIN: {
                    'trigger': {
                        'platform': 'sun',
                        'event': 'sunset',
                        'offset': '0:30:00'
                    },
                    'action': {
                        'service': 'test.automation',
                        'data_template': {
                            'some':
                            '{{ trigger.%s }}' % '}} - {{ trigger.'.join((
                                'platform', 'event', 'offset'))
                        },
                    }
                }
            })

        fire_time_changed(self.hass, trigger_time)
        self.hass.block_till_done()
        self.assertEqual(1, len(self.calls))
        self.assertEqual('sun - sunset - 0:30:00', self.calls[0].data['some'])
开发者ID:azogue,项目名称:home-assistant,代码行数:33,代码来源:test_sun.py

示例15: test_cancel_while_delay

    def test_cancel_while_delay(self):
        """Test the cancelling while the delay is present."""
        event = 'test_event'
        events = []

        @callback
        def record_event(event):
            """Add recorded event to set."""
            events.append(event)

        self.hass.bus.listen(event, record_event)

        script_obj = script.Script(self.hass, cv.SCRIPT_SCHEMA([
            {'delay': {'seconds': 5}},
            {'event': event}]))

        script_obj.run()

        self.hass.block_till_done()

        assert script_obj.is_running
        assert len(events) == 0

        script_obj.stop()

        assert not script_obj.is_running

        # Make sure the script is really stopped.
        future = dt_util.utcnow() + timedelta(seconds=5)
        fire_time_changed(self.hass, future)
        self.hass.block_till_done()

        assert not script_obj.is_running
        assert len(events) == 0
开发者ID:DavidLP,项目名称:home-assistant,代码行数:34,代码来源:test_script.py


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