コード例 #1
0
ファイル: test_climate.py プロジェクト: tpaulus/core
async def test_restore_state_climate(hass):
    """Run test for sensor restore state."""

    climate_name = "test_climate"
    test_temp = 37
    entity_id = f"{CLIMATE_DOMAIN}.{climate_name}"
    test_value = State(entity_id, 35)
    test_value.attributes = {ATTR_TEMPERATURE: test_temp}
    config_sensor = {
        CONF_NAME: climate_name,
        CONF_TARGET_TEMP: 117,
        CONF_CURRENT_TEMP: 117,
    }
    mock_restore_cache(
        hass,
        (test_value, ),
    )
    await base_config_test(
        hass,
        config_sensor,
        climate_name,
        CLIMATE_DOMAIN,
        CONF_CLIMATES,
        None,
        method_discovery=True,
    )
    state = hass.states.get(entity_id)
    assert state.state == HVAC_MODE_AUTO
    assert state.attributes[ATTR_TEMPERATURE] == test_temp
コード例 #2
0
                                               mock_modbus, mock_ha):
    """Test set_temperature."""
    mock_modbus.read_holding_registers.return_value = ReadResult(result)
    await hass.services.async_call(
        CLIMATE_DOMAIN,
        "set_temperature",
        {
            "entity_id": ENTITY_ID,
            ATTR_TEMPERATURE: temperature,
        },
        blocking=True,
    )


test_value = State(ENTITY_ID, 35)
test_value.attributes = {ATTR_TEMPERATURE: 37}


@pytest.mark.parametrize(
    "mock_test_state",
    [(test_value, )],
    indirect=True,
)
@pytest.mark.parametrize(
    "do_config",
    [
        {
            CONF_CLIMATES: [{
                CONF_NAME: TEST_ENTITY_NAME,
                CONF_TARGET_TEMP: 117,
                CONF_ADDRESS: 117,
コード例 #3
0
async def test_notifier_event_handler(hass, hass_admin_user, entry,
                                      mock_call_later):
    async_setup_notifier(hass)

    config = MockConfig(entry=entry(hass_admin_user, devices_discovered=True),
                        should_expose=lambda e: e != 'sensor.not_expose',
                        entity_config={
                            'switch.test': {
                                const.CONF_ENTITY_CUSTOM_MODES: {},
                                const.CONF_ENTITY_CUSTOM_TOGGLES: {},
                                const.CONF_ENTITY_CUSTOM_RANGES: {},
                                const.CONF_ENTITY_PROPERTIES: [{
                                    const.CONF_ENTITY_PROPERTY_TYPE:
                                    const.FLOAT_INSTANCE_HUMIDITY,
                                    const.CONF_ENTITY_PROPERTY_ENTITY:
                                    'sensor.humidity'
                                }]
                            }
                        })
    hass.data[DOMAIN] = {
        CONFIG: config,
        NOTIFIERS: [],
    }
    await async_start_notifier(hass)

    assert len(hass.data[DOMAIN][NOTIFIERS]) == 1
    notifier = hass.data[DOMAIN][NOTIFIERS][0]

    state_switch = State('switch.test',
                         STATE_ON,
                         attributes={ATTR_VOLTAGE: '3.5'})
    state_temp = State('sensor.temp',
                       '5',
                       attributes={
                           ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
                           ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
                       })
    state_humidity = State('sensor.humidity',
                           '95',
                           attributes={
                               ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
                               ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
                           })
    state_not_expose = State('sensor.not_expose',
                             '3',
                             attributes={
                                 ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
                                 ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
                             })
    for s in state_switch, state_temp, state_humidity, state_not_expose:
        hass.states.async_set(s.entity_id, s.state, s.attributes)

    await hass.async_block_till_done()
    assert len(notifier._pending) == 0

    for s in [STATE_UNAVAILABLE, STATE_UNKNOWN, None]:
        hass.states.async_set(state_temp.entity_id, s, state_temp.attributes)
        await hass.async_block_till_done()
        assert len(notifier._pending) == 0

    assert notifier._unsub_pending is None
    mock_call_later.reset_mock()
    hass.states.async_set(state_temp.entity_id, '6', state_temp.attributes)
    await hass.async_block_till_done()
    assert len(notifier._pending) == 1
    assert notifier._unsub_pending is not None
    mock_call_later.assert_called_once()
    assert '_report_states' in str(mock_call_later.call_args[0][2].target)
    mock_call_later.reset_mock()
    notifier._pending.clear()

    hass.states.async_set(state_not_expose.entity_id, '4',
                          state_not_expose.attributes)
    await hass.async_block_till_done()
    assert len(notifier._pending) == 0

    hass.states.async_set(state_humidity.entity_id, '60',
                          state_humidity.attributes)
    await hass.async_block_till_done()
    assert len(notifier._pending) == 2
    assert [c['id']
            for c in notifier._pending] == ['sensor.humidity', 'switch.test']
    mock_call_later.assert_not_called()
    notifier._pending.clear()

    state_switch.attributes = {
        ATTR_VOLTAGE: '3.5',
        ATTR_UNIT_OF_MEASUREMENT: 'V',
    }
    hass.states.async_set(state_switch.entity_id, state_switch.state,
                          state_switch.attributes)
    await hass.async_block_till_done()
    assert len(notifier._pending) == 0

    state_switch.attributes = {
        ATTR_VOLTAGE: '3',
        ATTR_UNIT_OF_MEASUREMENT: 'V',
    }
    hass.states.async_set(state_switch.entity_id, state_switch.state,
                          state_switch.attributes)
    await hass.async_block_till_done()
    assert len(notifier._pending) == 1
    notifier._pending.clear()

    hass.states.async_remove(state_switch.entity_id)
    hass.states.async_set(state_humidity.entity_id, '70',
                          state_humidity.attributes)
    await hass.async_block_till_done()

    async_unload_notifier(hass)