Exemplo n.º 1
0
    async def _async_test(
        bulb_type,
        model,
        target_properties,
        nightlight_properties=None,
        name=UNIQUE_NAME,
        entity_id=ENTITY_LIGHT,
    ):
        config_entry = MockConfigEntry(
            domain=DOMAIN,
            data={
                **CONFIG_ENTRY_DATA,
                CONF_NIGHTLIGHT_SWITCH: False,
            },
        )
        config_entry.add_to_hass(hass)

        mocked_bulb.bulb_type = bulb_type
        model_specs = _MODEL_SPECS.get(model)
        type(mocked_bulb).get_model_specs = MagicMock(return_value=model_specs)
        await _async_setup(config_entry)

        state = hass.states.get(entity_id)
        assert state.state == "on"
        target_properties["friendly_name"] = name
        target_properties["flowing"] = False
        target_properties["night_light"] = True
        assert dict(state.attributes) == target_properties

        await hass.config_entries.async_unload(config_entry.entry_id)
        await config_entry.async_remove(hass)
        registry = await entity_registry.async_get_registry(hass)
        registry.async_clear_config_entry(config_entry.entry_id)

        # nightlight
        if nightlight_properties is None:
            return
        config_entry = MockConfigEntry(
            domain=DOMAIN,
            data={
                **CONFIG_ENTRY_DATA,
                CONF_NIGHTLIGHT_SWITCH: True,
            },
        )
        config_entry.add_to_hass(hass)
        await _async_setup(config_entry)

        assert hass.states.get(entity_id).state == "off"
        state = hass.states.get(f"{entity_id}_nightlight")
        assert state.state == "on"
        nightlight_properties["friendly_name"] = f"{name} nightlight"
        nightlight_properties["icon"] = "mdi:weather-night"
        nightlight_properties["flowing"] = False
        nightlight_properties["night_light"] = True
        assert dict(state.attributes) == nightlight_properties

        await hass.config_entries.async_unload(config_entry.entry_id)
        await config_entry.async_remove(hass)
        registry.async_clear_config_entry(config_entry.entry_id)
Exemplo n.º 2
0
 def _create_mocked_bulb(bulb_type, model, unique_id):
     capabilities = {**CAPABILITIES}
     capabilities["id"] = f"yeelight.{unique_id}"
     mocked_bulb = _mocked_bulb()
     mocked_bulb.bulb_type = bulb_type
     mocked_bulb.last_properties = properties
     mocked_bulb.capabilities = capabilities
     model_specs = _MODEL_SPECS.get(model)
     type(mocked_bulb).get_model_specs = MagicMock(return_value=model_specs)
     return mocked_bulb
Exemplo n.º 3
0
    async def _async_test(
        bulb_type,
        model,
        target_properties,
        nightlight_properties=None,
        name=NAME,
        entity_id=ENTITY_LIGHT,
    ):
        config_entry = MockConfigEntry(
            domain=DOMAIN,
            data={
                CONF_ID: "",
                CONF_HOST: IP_ADDRESS,
                CONF_TRANSITION: DEFAULT_TRANSITION,
                CONF_MODE_MUSIC: DEFAULT_MODE_MUSIC,
                CONF_SAVE_ON_CHANGE: DEFAULT_SAVE_ON_CHANGE,
                CONF_NIGHTLIGHT_SWITCH: False,
            },
        )
        config_entry.add_to_hass(hass)

        mocked_bulb.bulb_type = bulb_type
        model_specs = _MODEL_SPECS.get(model)
        type(mocked_bulb).get_model_specs = MagicMock(return_value=model_specs)
        await _async_setup(config_entry)

        state = hass.states.get(entity_id)
        assert state.state == "on"
        target_properties["friendly_name"] = name
        target_properties["flowing"] = False
        target_properties["night_light"] = True
        assert dict(state.attributes) == target_properties

        await hass.config_entries.async_unload(config_entry.entry_id)
        await config_entry.async_remove(hass)

        # nightlight
        if nightlight_properties is None:
            return
        config_entry = MockConfigEntry(
            domain=DOMAIN,
            data={
                CONF_ID: "",
                CONF_HOST: IP_ADDRESS,
                CONF_TRANSITION: DEFAULT_TRANSITION,
                CONF_MODE_MUSIC: DEFAULT_MODE_MUSIC,
                CONF_SAVE_ON_CHANGE: DEFAULT_SAVE_ON_CHANGE,
                CONF_NIGHTLIGHT_SWITCH: True,
            },
        )
        config_entry.add_to_hass(hass)
        await _async_setup(config_entry)

        assert hass.states.get(entity_id).state == "off"
        state = hass.states.get(f"{entity_id}_nightlight")
        assert state.state == "on"
        nightlight_properties["friendly_name"] = f"{name} nightlight"
        nightlight_properties["icon"] = "mdi:weather-night"
        nightlight_properties["flowing"] = False
        nightlight_properties["night_light"] = True
        assert dict(state.attributes) == nightlight_properties

        await hass.config_entries.async_unload(config_entry.entry_id)
        await config_entry.async_remove(hass)