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


Python common.mock_component函数代码示例

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


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

示例1: test_force_update_enabled

    def test_force_update_enabled(self):
        """Test force update option."""
        mock_component(self.hass, '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',
                'force_update': True
            }
        })

        events = []

        @ha.callback
        def callback(event):
            """Verify event got called."""
            events.append(event)

        self.hass.bus.listen(EVENT_STATE_CHANGED, callback)

        fire_mqtt_message(self.hass, 'test-topic', 'ON')
        self.hass.block_till_done()
        self.assertEqual(1, len(events))

        fire_mqtt_message(self.hass, 'test-topic', 'ON')
        self.hass.block_till_done()
        self.assertEqual(2, len(events))
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:30,代码来源:test_mqtt.py

示例2: setup_comp

def setup_comp(hass):
    """Initialize components."""
    mock_component(hass, 'zone')
    yaml_devices = hass.config.path(device_tracker.YAML_DEVICES)
    yield
    if os.path.isfile(yaml_devices):
        os.remove(yaml_devices)
开发者ID:Martwall,项目名称:home-assistant,代码行数:7,代码来源:test_unifi_direct.py

示例3: test_caching_data

def test_caching_data(hass):
    """Test that we cache data."""
    mock_component(hass, 'recorder')
    hass.state = CoreState.starting

    states = [
        State('input_boolean.b0', 'on'),
        State('input_boolean.b1', 'on'),
        State('input_boolean.b2', 'on'),
    ]

    with patch('homeassistant.helpers.restore_state.last_recorder_run',
               return_value=MagicMock(end=dt_util.utcnow())), \
            patch('homeassistant.helpers.restore_state.get_states',
                  return_value=states), \
            patch('homeassistant.helpers.restore_state.wait_connection_ready',
                  return_value=mock_coro(True)):
        state = yield from async_get_last_state(hass, 'input_boolean.b1')

    assert DATA_RESTORE_CACHE in hass.data
    assert hass.data[DATA_RESTORE_CACHE] == {st.entity_id: st for st in states}

    assert state is not None
    assert state.entity_id == 'input_boolean.b1'
    assert state.state == 'on'

    hass.bus.async_fire(EVENT_HOMEASSISTANT_START)

    yield from hass.async_block_till_done()

    assert DATA_RESTORE_CACHE not in hass.data
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:31,代码来源:test_restore_state.py

示例4: test_restore_state

def test_restore_state(hass):
    """Test state gets restored."""
    mock_component(hass, 'recorder')
    hass.state = CoreState.starting
    hass.data[DATA_RESTORE_CACHE] = {
        'light.bed_light': State('light.bed_light', 'on', {
            'brightness': 'value-brightness',
            'color_temp': 'value-color_temp',
            'rgb_color': 'value-rgb_color',
            'xy_color': 'value-xy_color',
            'white_value': 'value-white_value',
            'effect': 'value-effect',
        }),
    }

    yield from async_setup_component(hass, 'light', {
        'light': {
            'platform': 'demo',
        }})

    state = hass.states.get('light.bed_light')
    assert state is not None
    assert state.entity_id == 'light.bed_light'
    assert state.state == 'on'
    assert state.attributes.get('brightness') == 'value-brightness'
    assert state.attributes.get('color_temp') == 'value-color_temp'
    assert state.attributes.get('rgb_color') == 'value-rgb_color'
    assert state.attributes.get('xy_color') == 'value-xy_color'
    assert state.attributes.get('white_value') == 'value-white_value'
    assert state.attributes.get('effect') == 'value-effect'
开发者ID:tedstriker,项目名称:home-assistant,代码行数:30,代码来源:test_demo.py

示例5: setup_method

    def setup_method(self):
        """Set up things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        mock_component(self.hass, 'zone')
        mock_component(self.hass, 'group')

        self.host = "127.0.0.1"
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:7,代码来源:test_upc_connect.py

示例6: test_restore_state

def test_restore_state(hass):
    """Ensure states are restored on startup."""
    hass.data[DATA_RESTORE_CACHE] = {
        'binary_sensor.test': State('binary_sensor.test', 'on'),
    }

    hass.state = CoreState.starting
    mock_component(hass, 'recorder')

    config = {
        'binary_sensor': {
            'platform': 'template',
            'sensors': {
                'test': {
                    'friendly_name': 'virtual thingy',
                    'value_template':
                        "{{ states.sensor.test_state.state == 'on' }}",
                    'device_class': 'motion',
                },
            },
        },
    }
    yield from setup.async_setup_component(hass, 'binary_sensor', config)

    state = hass.states.get('binary_sensor.test')
    assert state.state == 'on'

    yield from hass.async_start()
    yield from hass.async_block_till_done()

    state = hass.states.get('binary_sensor.test')
    assert state.state == 'off'
开发者ID:Khabi,项目名称:home-assistant,代码行数:32,代码来源:test_template.py

示例7: test_force_update_enabled

    def test_force_update_enabled(self):
        """Test force update option."""
        mock_component(self.hass, 'mqtt')
        assert setup_component(self.hass, sensor.DOMAIN, {
            sensor.DOMAIN: {
                'platform': 'mqtt',
                'name': 'test',
                'state_topic': 'test-topic',
                'unit_of_measurement': 'fav unit',
                'force_update': True
            }
        })

        events = []

        @ha.callback
        def callback(event):
            events.append(event)

        self.hass.bus.listen(EVENT_STATE_CHANGED, callback)

        fire_mqtt_message(self.hass, 'test-topic', '100')
        self.hass.block_till_done()
        self.assertEqual(1, len(events))

        fire_mqtt_message(self.hass, 'test-topic', '100')
        self.hass.block_till_done()
        self.assertEqual(2, len(events))
开发者ID:tucka,项目名称:home-assistant,代码行数:28,代码来源:test_mqtt.py

示例8: test_restore_state

def test_restore_state(hass):
    """Ensure states are restored on startup."""
    hass.data[DATA_RESTORE_CACHE] = {
        'input_slider.b1': State('input_slider.b1', '70'),
        'input_slider.b2': State('input_slider.b2', '200'),
    }

    hass.state = CoreState.starting
    mock_component(hass, 'recorder')

    yield from async_setup_component(hass, DOMAIN, {
        DOMAIN: {
            'b1': {
                'initial': 50,
                'min': 0,
                'max': 100,
            },
            'b2': {
                'initial': 60,
                'min': 0,
                'max': 100,
            },
        }})

    state = hass.states.get('input_slider.b1')
    assert state
    assert float(state.state) == 70

    state = hass.states.get('input_slider.b2')
    assert state
    assert float(state.state) == 60
开发者ID:nunofgs,项目名称:home-assistant,代码行数:31,代码来源:test_input_slider.py

示例9: setup_comp

def setup_comp(hass):
    """Initialize components."""
    mock_component(hass, 'group')
    hass.loop.run_until_complete(async_setup_component(hass, zone.DOMAIN, {
            'zone': {
                'name': 'test',
                'latitude': 32.880837,
                'longitude': -117.237561,
                'radius': 250,
            }
        }))
开发者ID:boced66,项目名称:home-assistant,代码行数:11,代码来源:test_geo_location.py

示例10: test_receive_mqtt_temperature

    def test_receive_mqtt_temperature(self):
        """Test getting the current temperature via MQTT."""
        config = copy.deepcopy(DEFAULT_CONFIG)
        config['climate']['current_temperature_topic'] = 'current_temperature'
        mock_component(self.hass, 'mqtt')
        assert setup_component(self.hass, climate.DOMAIN, config)

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

示例11: setUp

    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        mock_component(self.hass, 'group')
        self.calls = []

        @callback
        def record_call(service):
            """Helper to record calls."""
            self.calls.append(service)

        self.hass.services.register('test', 'automation', record_call)
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:12,代码来源:test_numeric_state.py

示例12: mock_client

def mock_client(hass, test_client):
    """Start the Hass HTTP component."""
    mock_component(hass, 'group')
    mock_component(hass, 'zone')
    with patch('homeassistant.components.device_tracker.async_load_config',
               return_value=mock_coro([])):
        hass.loop.run_until_complete(
            async_setup_component(hass, 'device_tracker', {
                'device_tracker': {
                    'platform': 'owntracks_http'
                }
            }))
    return hass.loop.run_until_complete(test_client(hass.http.app))
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:13,代码来源:test_owntracks_http.py

示例13: test_load_on_demand_already_loaded

def test_load_on_demand_already_loaded(hass, test_client):
    """Test getting suites."""
    mock_component(hass, 'zwave')

    with patch.object(config, 'SECTIONS', []), \
            patch.object(config, 'ON_DEMAND', ['zwave']), \
            patch('homeassistant.components.config.zwave.async_setup') as stp:
        stp.return_value = mock_coro(True)

        yield from async_setup_component(hass, 'config', {})

    yield from hass.async_block_till_done()
    assert 'config.zwave' in hass.config.components
    assert stp.called
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:14,代码来源:test_init.py

示例14: test_not_connected

def test_not_connected(hass):
    """Test that cache cannot be accessed if db connection times out."""
    mock_component(hass, 'recorder')
    hass.state = CoreState.starting

    states = [State('input_boolean.b1', 'on')]

    with patch('homeassistant.helpers.restore_state.last_recorder_run',
               return_value=MagicMock(end=dt_util.utcnow())), \
            patch('homeassistant.helpers.restore_state.get_states',
                  return_value=states), \
            patch('homeassistant.helpers.restore_state.wait_connection_ready',
                  return_value=mock_coro(False)):
        state = yield from async_get_last_state(hass, 'input_boolean.b1')
    assert state is None
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:15,代码来源:test_restore_state.py

示例15: setUp

    def setUp(self):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        mock_component(self.hass, 'group')
        setup_component(self.hass, sun.DOMAIN, {
            sun.DOMAIN: {sun.CONF_ELEVATION: 0}})

        self.calls = []

        @callback
        def record_call(service):
            """Call recorder."""
            self.calls.append(service)

        self.hass.services.register('test', 'automation', record_call)
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:15,代码来源:test_sun.py


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