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


Python common.async_mock_service函数代码示例

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


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

示例1: test_onoff_fan

async def test_onoff_fan(hass):
    """Test OnOff trait support for fan domain."""
    assert trait.OnOffTrait.supported(fan.DOMAIN, 0)

    trt_on = trait.OnOffTrait(hass, State('fan.bla', STATE_ON), BASIC_CONFIG)

    assert trt_on.sync_attributes() == {}

    assert trt_on.query_attributes() == {
        'on': True
    }

    trt_off = trait.OnOffTrait(hass, State('fan.bla', STATE_OFF), BASIC_CONFIG)
    assert trt_off.query_attributes() == {
        'on': False
    }

    on_calls = async_mock_service(hass, fan.DOMAIN, SERVICE_TURN_ON)
    await trt_on.execute(
        trait.COMMAND_ONOFF, BASIC_DATA,
        {'on': True})
    assert len(on_calls) == 1
    assert on_calls[0].data == {
        ATTR_ENTITY_ID: 'fan.bla',
    }

    off_calls = async_mock_service(hass, fan.DOMAIN, SERVICE_TURN_OFF)
    await trt_on.execute(
        trait.COMMAND_ONOFF, BASIC_DATA,
        {'on': False})
    assert len(off_calls) == 1
    assert off_calls[0].data == {
        ATTR_ENTITY_ID: 'fan.bla',
    }
开发者ID:boced66,项目名称:home-assistant,代码行数:34,代码来源:test_trait.py

示例2: test_api_turn_off

def test_api_turn_off(hass, domain):
    """Test api turn on process."""
    request = get_new_request(
        'Alexa.PowerController', 'TurnOff', '{}#test'.format(domain))

    # setup test devices
    hass.states.async_set(
        '{}.test'.format(domain), 'on', {
            'friendly_name': "Test {}".format(domain)
        })

    call_domain = domain

    if domain == 'group':
        call_domain = 'homeassistant'

    if domain == 'cover':
        call = async_mock_service(hass, call_domain, 'close_cover')
    else:
        call = async_mock_service(hass, call_domain, 'turn_off')

    msg = yield from smart_home.async_handle_message(
        hass, DEFAULT_CONFIG, request)
    yield from hass.async_block_till_done()

    assert 'event' in msg
    msg = msg['event']

    assert len(call) == 1
    assert call[0].data['entity_id'] == '{}.test'.format(domain)
    assert msg['header']['name'] == 'Response'
开发者ID:lexam79,项目名称:home-assistant,代码行数:31,代码来源:test_smart_home.py

示例3: test_reset_switch

async def test_reset_switch(hass, hk_driver, entity_id, attrs, events):
    """Test if switch accessory is reset correctly."""
    domain = split_entity_id(entity_id)[0]

    hass.states.async_set(entity_id, None, attrs)
    await hass.async_block_till_done()
    acc = Switch(hass, hk_driver, 'Switch', entity_id, 2, None)
    await hass.async_add_job(acc.run)
    await hass.async_block_till_done()

    assert acc.activate_only is True
    assert acc.char_on.value is False

    call_turn_on = async_mock_service(hass, domain, 'turn_on')
    call_turn_off = async_mock_service(hass, domain, 'turn_off')

    await hass.async_add_job(acc.char_on.client_update_value, True)
    await hass.async_block_till_done()
    assert acc.char_on.value is True
    assert call_turn_on
    assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
    assert len(events) == 1
    assert events[-1].data[ATTR_VALUE] is None

    future = dt_util.utcnow() + timedelta(seconds=1)
    async_fire_time_changed(hass, future)
    await hass.async_block_till_done()
    assert acc.char_on.value is False
    assert len(events) == 1
    assert not call_turn_off

    await hass.async_add_job(acc.char_on.client_update_value, False)
    await hass.async_block_till_done()
    assert acc.char_on.value is False
    assert len(events) == 1
开发者ID:Martwall,项目名称:home-assistant,代码行数:35,代码来源:test_type_switches.py

示例4: test_onoff_media_player

async def test_onoff_media_player(hass):
    """Test OnOff trait support for media_player domain."""
    assert trait.OnOffTrait.supported(media_player.DOMAIN, 0)

    trt_on = trait.OnOffTrait(State('media_player.bla', STATE_ON))

    assert trt_on.sync_attributes() == {}

    assert trt_on.query_attributes() == {
        'on': True
    }

    trt_off = trait.OnOffTrait(State('media_player.bla', STATE_OFF))
    assert trt_off.query_attributes() == {
        'on': False
    }

    on_calls = async_mock_service(hass, media_player.DOMAIN, SERVICE_TURN_ON)
    await trt_on.execute(hass, trait.COMMAND_ONOFF, {
        'on': True
    })
    assert len(on_calls) == 1
    assert on_calls[0].data == {
        ATTR_ENTITY_ID: 'media_player.bla',
    }

    off_calls = async_mock_service(hass, media_player.DOMAIN, SERVICE_TURN_OFF)
    await trt_on.execute(hass, trait.COMMAND_ONOFF, {
        'on': False
    })
    assert len(off_calls) == 1
    assert off_calls[0].data == {
        ATTR_ENTITY_ID: 'media_player.bla',
    }
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:34,代码来源:test_trait.py

示例5: test_thermostat_power_state

async def test_thermostat_power_state(hass, hk_driver, cls, events):
    """Test if accessory and HA are updated accordingly."""
    entity_id = 'climate.test'

    # SUPPORT_ON_OFF = True
    hass.states.async_set(entity_id, STATE_HEAT,
                          {ATTR_SUPPORTED_FEATURES: 4096,
                           ATTR_OPERATION_MODE: STATE_HEAT,
                           ATTR_TEMPERATURE: 23.0,
                           ATTR_CURRENT_TEMPERATURE: 18.0})
    await hass.async_block_till_done()
    acc = cls.thermostat(hass, hk_driver, 'Climate', entity_id, 2, None)
    await hass.async_add_job(acc.run)
    await hass.async_block_till_done()
    assert acc.support_power_state is True

    assert acc.char_current_heat_cool.value == 1
    assert acc.char_target_heat_cool.value == 1

    hass.states.async_set(entity_id, STATE_OFF,
                          {ATTR_OPERATION_MODE: STATE_HEAT,
                           ATTR_TEMPERATURE: 23.0,
                           ATTR_CURRENT_TEMPERATURE: 18.0})
    await hass.async_block_till_done()
    assert acc.char_current_heat_cool.value == 0
    assert acc.char_target_heat_cool.value == 0

    hass.states.async_set(entity_id, STATE_OFF,
                          {ATTR_OPERATION_MODE: STATE_OFF,
                           ATTR_TEMPERATURE: 23.0,
                           ATTR_CURRENT_TEMPERATURE: 18.0})
    await hass.async_block_till_done()
    assert acc.char_current_heat_cool.value == 0
    assert acc.char_target_heat_cool.value == 0

    # Set from HomeKit
    call_turn_on = async_mock_service(hass, DOMAIN_CLIMATE, 'turn_on')
    call_turn_off = async_mock_service(hass, DOMAIN_CLIMATE, 'turn_off')
    call_set_operation_mode = async_mock_service(hass, DOMAIN_CLIMATE,
                                                 'set_operation_mode')

    await hass.async_add_job(acc.char_target_heat_cool.client_update_value, 1)
    await hass.async_block_till_done()
    assert call_turn_on
    assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
    assert call_set_operation_mode
    assert call_set_operation_mode[0].data[ATTR_ENTITY_ID] == entity_id
    assert call_set_operation_mode[0].data[ATTR_OPERATION_MODE] == STATE_HEAT
    assert acc.char_target_heat_cool.value == 1
    assert len(events) == 2
    assert events[-1].data[ATTR_VALUE] == STATE_HEAT

    await hass.async_add_job(acc.char_target_heat_cool.client_update_value, 0)
    await hass.async_block_till_done()
    assert call_turn_off
    assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id
    assert acc.char_target_heat_cool.value == 0
    assert len(events) == 3
    assert events[-1].data[ATTR_VALUE] is None
开发者ID:ManHammer,项目名称:home-assistant,代码行数:59,代码来源:test_type_thermostats.py

示例6: test_garage_door_open_close

async def test_garage_door_open_close(hass, hk_driver, cls, events):
    """Test if accessory and HA are updated accordingly."""
    entity_id = 'cover.garage_door'

    hass.states.async_set(entity_id, None)
    await hass.async_block_till_done()
    acc = cls.garage(hass, hk_driver, 'Garage Door', entity_id, 2, None)
    await hass.async_add_job(acc.run)

    assert acc.aid == 2
    assert acc.category == 4  # GarageDoorOpener

    assert acc.char_current_state.value == 0
    assert acc.char_target_state.value == 0

    hass.states.async_set(entity_id, STATE_CLOSED)
    await hass.async_block_till_done()
    assert acc.char_current_state.value == 1
    assert acc.char_target_state.value == 1

    hass.states.async_set(entity_id, STATE_OPEN)
    await hass.async_block_till_done()
    assert acc.char_current_state.value == 0
    assert acc.char_target_state.value == 0

    hass.states.async_set(entity_id, STATE_UNAVAILABLE)
    await hass.async_block_till_done()
    assert acc.char_current_state.value == 0
    assert acc.char_target_state.value == 0

    hass.states.async_set(entity_id, STATE_UNKNOWN)
    await hass.async_block_till_done()
    assert acc.char_current_state.value == 0
    assert acc.char_target_state.value == 0

    # Set from HomeKit
    call_close_cover = async_mock_service(hass, DOMAIN, 'close_cover')
    call_open_cover = async_mock_service(hass, DOMAIN, 'open_cover')

    await hass.async_add_job(acc.char_target_state.client_update_value, 1)
    await hass.async_block_till_done()
    assert call_close_cover
    assert call_close_cover[0].data[ATTR_ENTITY_ID] == entity_id
    assert acc.char_current_state.value == 2
    assert acc.char_target_state.value == 1
    assert len(events) == 1
    assert events[-1].data[ATTR_VALUE] is None

    hass.states.async_set(entity_id, STATE_CLOSED)
    await hass.async_block_till_done()

    await hass.async_add_job(acc.char_target_state.client_update_value, 0)
    await hass.async_block_till_done()
    assert call_open_cover
    assert call_open_cover[0].data[ATTR_ENTITY_ID] == entity_id
    assert acc.char_current_state.value == 3
    assert acc.char_target_state.value == 0
    assert len(events) == 2
    assert events[-1].data[ATTR_VALUE] is None
开发者ID:ManHammer,项目名称:home-assistant,代码行数:59,代码来源:test_type_covers.py

示例7: test_lock_unlock

async def test_lock_unlock(hass, hk_driver, events):
    """Test if accessory and HA are updated accordingly."""
    code = '1234'
    config = {ATTR_CODE: code}
    entity_id = 'lock.kitchen_door'

    hass.states.async_set(entity_id, None)
    await hass.async_block_till_done()
    acc = Lock(hass, hk_driver, 'Lock', entity_id, 2, config)
    await hass.async_add_job(acc.run)

    assert acc.aid == 2
    assert acc.category == 6  # DoorLock

    assert acc.char_current_state.value == 3
    assert acc.char_target_state.value == 1

    hass.states.async_set(entity_id, STATE_LOCKED)
    await hass.async_block_till_done()
    assert acc.char_current_state.value == 1
    assert acc.char_target_state.value == 1

    hass.states.async_set(entity_id, STATE_UNLOCKED)
    await hass.async_block_till_done()
    assert acc.char_current_state.value == 0
    assert acc.char_target_state.value == 0

    hass.states.async_set(entity_id, STATE_UNKNOWN)
    await hass.async_block_till_done()
    assert acc.char_current_state.value == 3
    assert acc.char_target_state.value == 0

    hass.states.async_remove(entity_id)
    await hass.async_block_till_done()
    assert acc.char_current_state.value == 3
    assert acc.char_target_state.value == 0

    # Set from HomeKit
    call_lock = async_mock_service(hass, DOMAIN, 'lock')
    call_unlock = async_mock_service(hass, DOMAIN, 'unlock')

    await hass.async_add_job(acc.char_target_state.client_update_value, 1)
    await hass.async_block_till_done()
    assert call_lock
    assert call_lock[0].data[ATTR_ENTITY_ID] == entity_id
    assert call_lock[0].data[ATTR_CODE] == code
    assert acc.char_target_state.value == 1
    assert len(events) == 1
    assert events[-1].data[ATTR_VALUE] is None

    await hass.async_add_job(acc.char_target_state.client_update_value, 0)
    await hass.async_block_till_done()
    assert call_unlock
    assert call_unlock[0].data[ATTR_ENTITY_ID] == entity_id
    assert call_unlock[0].data[ATTR_CODE] == code
    assert acc.char_target_state.value == 0
    assert len(events) == 2
    assert events[-1].data[ATTR_VALUE] is None
开发者ID:ManHammer,项目名称:home-assistant,代码行数:58,代码来源:test_type_locks.py

示例8: test_setup_user_notify_service

async def test_setup_user_notify_service(hass):
    """Test allow select notify service during mfa setup."""
    notify_calls = async_mock_service(
        hass, 'notify', 'test1', NOTIFY_SERVICE_SCHEMA)
    async_mock_service(hass, 'notify', 'test2', NOTIFY_SERVICE_SCHEMA)
    notify_auth_module = await auth_mfa_module_from_config(hass, {
        'type': 'notify',
    })

    services = notify_auth_module.aync_get_available_notify_services()
    assert services == ['test1', 'test2']

    flow = await notify_auth_module.async_setup_flow('test-user')
    step = await flow.async_step_init()
    assert step['type'] == data_entry_flow.RESULT_TYPE_FORM
    assert step['step_id'] == 'init'
    schema = step['data_schema']
    schema({'notify_service': 'test2'})

    with patch('pyotp.HOTP.at', return_value=MOCK_CODE):
        step = await flow.async_step_init({'notify_service': 'test1'})
        assert step['type'] == data_entry_flow.RESULT_TYPE_FORM
        assert step['step_id'] == 'setup'

    # wait service call finished
    await hass.async_block_till_done()

    assert len(notify_calls) == 1
    notify_call = notify_calls[0]
    assert notify_call.domain == 'notify'
    assert notify_call.service == 'test1'
    message = notify_call.data['message']
    message.hass = hass
    assert MOCK_CODE in message.async_render()

    with patch('pyotp.HOTP.at', return_value=MOCK_CODE_2):
        step = await flow.async_step_setup({'code': 'invalid'})
        assert step['type'] == data_entry_flow.RESULT_TYPE_FORM
        assert step['step_id'] == 'setup'
        assert step['errors']['base'] == 'invalid_code'

    # wait service call finished
    await hass.async_block_till_done()

    assert len(notify_calls) == 2
    notify_call = notify_calls[1]
    assert notify_call.domain == 'notify'
    assert notify_call.service == 'test1'
    message = notify_call.data['message']
    message.hass = hass
    assert MOCK_CODE_2 in message.async_render()

    with patch('pyotp.HOTP.verify', return_value=True):
        step = await flow.async_step_setup({'code': MOCK_CODE_2})
        assert step['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
开发者ID:Martwall,项目名称:home-assistant,代码行数:55,代码来源:test_notify.py

示例9: test_fan_basic

async def test_fan_basic(hass, hk_driver, cls, events):
    """Test fan with char state."""
    entity_id = 'fan.demo'

    hass.states.async_set(entity_id, STATE_ON, {ATTR_SUPPORTED_FEATURES: 0})
    await hass.async_block_till_done()
    acc = cls.fan(hass, hk_driver, 'Fan', entity_id, 2, None)

    assert acc.aid == 2
    assert acc.category == 3  # Fan
    assert acc.char_active.value == 0

    # If there are no speed_list values, then HomeKit speed is unsupported
    assert acc.char_speed is None

    await hass.async_add_job(acc.run)
    await hass.async_block_till_done()
    assert acc.char_active.value == 1

    hass.states.async_set(entity_id, STATE_OFF, {ATTR_SUPPORTED_FEATURES: 0})
    await hass.async_block_till_done()
    assert acc.char_active.value == 0

    hass.states.async_set(entity_id, STATE_UNKNOWN)
    await hass.async_block_till_done()
    assert acc.char_active.value == 0

    hass.states.async_remove(entity_id)
    await hass.async_block_till_done()
    assert acc.char_active.value == 0

    # Set from HomeKit
    call_turn_on = async_mock_service(hass, DOMAIN, 'turn_on')
    call_turn_off = async_mock_service(hass, DOMAIN, 'turn_off')

    await hass.async_add_job(acc.char_active.client_update_value, 1)
    await hass.async_block_till_done()
    assert call_turn_on
    assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
    assert len(events) == 1
    assert events[-1].data[ATTR_VALUE] is None

    hass.states.async_set(entity_id, STATE_ON)
    await hass.async_block_till_done()

    await hass.async_add_job(acc.char_active.client_update_value, 0)
    await hass.async_block_till_done()
    assert call_turn_off
    assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id
    assert len(events) == 2
    assert events[-1].data[ATTR_VALUE] is None
开发者ID:arsaboo,项目名称:home-assistant,代码行数:51,代码来源:test_type_fans.py

示例10: test_setup_user_no_notify_service

async def test_setup_user_no_notify_service(hass):
    """Test setup flow abort if there is no avilable notify service."""
    async_mock_service(hass, 'notify', 'test1', NOTIFY_SERVICE_SCHEMA)
    notify_auth_module = await auth_mfa_module_from_config(hass, {
        'type': 'notify',
        'exclude': 'test1',
    })

    services = notify_auth_module.aync_get_available_notify_services()
    assert services == []

    flow = await notify_auth_module.async_setup_flow('test-user')
    step = await flow.async_step_init()
    assert step['type'] == data_entry_flow.RESULT_TYPE_ABORT
    assert step['reason'] == 'no_available_service'
开发者ID:Martwall,项目名称:home-assistant,代码行数:15,代码来源:test_notify.py

示例11: test_light_basic

async def test_light_basic(hass, hk_driver, cls, events):
    """Test light with char state."""
    entity_id = 'light.demo'

    hass.states.async_set(entity_id, STATE_ON, {ATTR_SUPPORTED_FEATURES: 0})
    await hass.async_block_till_done()
    acc = cls.light(hass, hk_driver, 'Light', entity_id, 2, None)

    assert acc.aid == 2
    assert acc.category == 5  # Lightbulb
    assert acc.char_on.value == 0

    await hass.async_add_job(acc.run)
    await hass.async_block_till_done()
    assert acc.char_on.value == 1

    hass.states.async_set(entity_id, STATE_OFF, {ATTR_SUPPORTED_FEATURES: 0})
    await hass.async_block_till_done()
    assert acc.char_on.value == 0

    hass.states.async_set(entity_id, STATE_UNKNOWN)
    await hass.async_block_till_done()
    assert acc.char_on.value == 0

    hass.states.async_remove(entity_id)
    await hass.async_block_till_done()
    assert acc.char_on.value == 0

    # Set from HomeKit
    call_turn_on = async_mock_service(hass, DOMAIN, 'turn_on')
    call_turn_off = async_mock_service(hass, DOMAIN, 'turn_off')

    await hass.async_add_job(acc.char_on.client_update_value, 1)
    await hass.async_block_till_done()
    assert call_turn_on
    assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
    assert len(events) == 1
    assert events[-1].data[ATTR_VALUE] is None

    hass.states.async_set(entity_id, STATE_ON)
    await hass.async_block_till_done()

    await hass.async_add_job(acc.char_on.client_update_value, 0)
    await hass.async_block_till_done()
    assert call_turn_off
    assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id
    assert len(events) == 2
    assert events[-1].data[ATTR_VALUE] is None
开发者ID:ManHammer,项目名称:home-assistant,代码行数:48,代码来源:test_type_lights.py

示例12: test_light_brightness

async def test_light_brightness(hass, hk_driver, cls, events):
    """Test light with brightness."""
    entity_id = 'light.demo'

    hass.states.async_set(entity_id, STATE_ON, {
        ATTR_SUPPORTED_FEATURES: SUPPORT_BRIGHTNESS, ATTR_BRIGHTNESS: 255})
    await hass.async_block_till_done()
    acc = cls.light(hass, hk_driver, 'Light', entity_id, 2, None)

    assert acc.char_brightness.value == 0

    await hass.async_add_job(acc.run)
    await hass.async_block_till_done()
    assert acc.char_brightness.value == 100

    hass.states.async_set(entity_id, STATE_ON, {ATTR_BRIGHTNESS: 102})
    await hass.async_block_till_done()
    assert acc.char_brightness.value == 40

    # Set from HomeKit
    call_turn_on = async_mock_service(hass, DOMAIN, 'turn_on')
    call_turn_off = async_mock_service(hass, DOMAIN, 'turn_off')

    await hass.async_add_job(acc.char_brightness.client_update_value, 20)
    await hass.async_add_job(acc.char_on.client_update_value, 1)
    await hass.async_block_till_done()
    assert call_turn_on[0]
    assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
    assert call_turn_on[0].data[ATTR_BRIGHTNESS_PCT] == 20
    assert len(events) == 1
    assert events[-1].data[ATTR_VALUE] == 'brightness at 20%'

    await hass.async_add_job(acc.char_on.client_update_value, 1)
    await hass.async_add_job(acc.char_brightness.client_update_value, 40)
    await hass.async_block_till_done()
    assert call_turn_on[1]
    assert call_turn_on[1].data[ATTR_ENTITY_ID] == entity_id
    assert call_turn_on[1].data[ATTR_BRIGHTNESS_PCT] == 40
    assert len(events) == 2
    assert events[-1].data[ATTR_VALUE] == 'brightness at 40%'

    await hass.async_add_job(acc.char_on.client_update_value, 1)
    await hass.async_add_job(acc.char_brightness.client_update_value, 0)
    await hass.async_block_till_done()
    assert call_turn_off
    assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id
    assert len(events) == 3
    assert events[-1].data[ATTR_VALUE] is None
开发者ID:ManHammer,项目名称:home-assistant,代码行数:48,代码来源:test_type_lights.py

示例13: test_api_decrease_color_temp

def test_api_decrease_color_temp(hass, result, initial):
    """Test api decrease color temp process."""
    request = get_new_request(
        'Alexa.ColorTemperatureController', 'DecreaseColorTemperature',
        'light#test')

    # setup test devices
    hass.states.async_set(
        'light.test', 'off', {
            'friendly_name': "Test light", 'color_temp': initial,
            'max_mireds': 500,
        })

    call_light = async_mock_service(hass, 'light', 'turn_on')

    msg = yield from smart_home.async_handle_message(
        hass, DEFAULT_CONFIG, request)
    yield from hass.async_block_till_done()

    assert 'event' in msg
    msg = msg['event']

    assert len(call_light) == 1
    assert call_light[0].data['entity_id'] == 'light.test'
    assert call_light[0].data['color_temp'] == result
    assert msg['header']['name'] == 'Response'
开发者ID:TheRealLink,项目名称:home-assistant,代码行数:26,代码来源:test_smart_home.py

示例14: test_api_set_color_temperature

def test_api_set_color_temperature(hass):
    """Test api set color temperature process."""
    request = get_new_request(
        'Alexa.ColorTemperatureController', 'SetColorTemperature',
        'light#test')

    # add payload
    request['directive']['payload']['colorTemperatureInKelvin'] = '7500'

    # setup test devices
    hass.states.async_set(
        'light.test', 'off', {'friendly_name': "Test light"})

    call_light = async_mock_service(hass, 'light', 'turn_on')

    msg = yield from smart_home.async_handle_message(
        hass, DEFAULT_CONFIG, request)
    yield from hass.async_block_till_done()

    assert 'event' in msg
    msg = msg['event']

    assert len(call_light) == 1
    assert call_light[0].data['entity_id'] == 'light.test'
    assert call_light[0].data['kelvin'] == 7500
    assert msg['header']['name'] == 'Response'
开发者ID:TheRealLink,项目名称:home-assistant,代码行数:26,代码来源:test_smart_home.py

示例15: test_api_set_color_rgb

def test_api_set_color_rgb(hass):
    """Test api set color process."""
    request = get_new_request(
        'Alexa.ColorController', 'SetColor', 'light#test')

    # add payload
    request['directive']['payload']['color'] = {
        'hue': '120',
        'saturation': '0.612',
        'brightness': '0.342',
    }

    # setup test devices
    hass.states.async_set(
        'light.test', 'off', {
            'friendly_name': "Test light",
            'supported_features': 16,
        })

    call_light = async_mock_service(hass, 'light', 'turn_on')

    msg = yield from smart_home.async_handle_message(
        hass, DEFAULT_CONFIG, request)
    yield from hass.async_block_till_done()

    assert 'event' in msg
    msg = msg['event']

    assert len(call_light) == 1
    assert call_light[0].data['entity_id'] == 'light.test'
    assert call_light[0].data['rgb_color'] == (33, 87, 33)
    assert msg['header']['name'] == 'Response'
开发者ID:TheRealLink,项目名称:home-assistant,代码行数:32,代码来源:test_smart_home.py


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