Exemple #1
0
async def test_source_state_none(hass, recorder_mock, values):
    """Test is source sensor state is null and sets state to STATE_UNKNOWN."""

    config = {
        "sensor": [
            {
                "platform": "template",
                "sensors": {
                    "template_test": {
                        "value_template": "{{ states.sensor.test_state.state }}"
                    }
                },
            },
            {
                "platform": "filter",
                "name": "test",
                "entity_id": "sensor.template_test",
                "filters": [
                    {
                        "filter": "time_simple_moving_average",
                        "window_size": "00:01",
                        "precision": "2",
                    }
                ],
            },
        ]
    }
    await async_setup_component(hass, "sensor", config)
    await hass.async_block_till_done()

    hass.states.async_set("sensor.test_state", 0)

    await hass.async_block_till_done()
    state = hass.states.get("sensor.template_test")
    assert state.state == "0"

    await hass.async_block_till_done()
    state = hass.states.get("sensor.test")
    assert state.state == "0.0"

    # Force Template Reload
    yaml_path = get_fixture_path("sensor_configuration.yaml", "template")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            "template",
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    # Template state gets to None
    state = hass.states.get("sensor.template_test")
    assert state is None

    # Filter sensor ignores None state setting state to STATE_UNKNOWN
    state = hass.states.get("sensor.test")
    assert state.state == STATE_UNKNOWN
Exemple #2
0
async def test_reload(hass):
    """Verify we can reload filter sensors."""
    await async_init_recorder_component(hass)

    hass.states.async_set("sensor.test_monitored", 12345)
    await async_setup_component(
        hass,
        "sensor",
        {
            "sensor": {
                "platform":
                "filter",
                "name":
                "test",
                "entity_id":
                "sensor.test_monitored",
                "filters": [
                    {
                        "filter": "outlier",
                        "window_size": 10,
                        "radius": 4.0
                    },
                    {
                        "filter": "lowpass",
                        "time_constant": 10,
                        "precision": 2
                    },
                    {
                        "filter": "throttle",
                        "window_size": 1
                    },
                ],
            }
        },
    )
    await hass.async_block_till_done()
    await hass.async_start()
    await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 2

    assert hass.states.get("sensor.test")

    yaml_path = get_fixture_path("configuration.yaml", "filter")

    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 2

    assert hass.states.get("sensor.test") is None
    assert hass.states.get("sensor.filtered_realistic_humidity")
Exemple #3
0
async def mock_vehicles_from_fixture(account: MyBMWAccount) -> None:
    """Load MyBMWVehicle from fixtures and add them to the account."""

    fixture_path = Path(get_fixture_path("", integration=BMW_DOMAIN))

    fixture_vehicles_bmw = list(fixture_path.rglob("vehicles_v2_bmw_*.json"))
    fixture_vehicles_mini = list(fixture_path.rglob("vehicles_v2_mini_*.json"))

    # Load vehicle base lists as provided by vehicles/v2 API
    vehicles = {
        "bmw": [
            vehicle for bmw_file in fixture_vehicles_bmw
            for vehicle in json.loads(
                load_fixture(bmw_file, integration=BMW_DOMAIN))
        ],
        "mini": [
            vehicle for mini_file in fixture_vehicles_mini
            for vehicle in json.loads(
                load_fixture(mini_file, integration=BMW_DOMAIN))
        ],
    }
    fetched_at = utcnow()

    # simulate storing fingerprints
    if account.config.log_response_path:
        for brand in ["bmw", "mini"]:
            log_to_to_file(
                json.dumps(vehicles[brand]),
                account.config.log_response_path,
                f"vehicles_v2_{brand}",
            )

    # Create a vehicle with base + specific state as provided by state/VIN API
    for vehicle_base in [
            vehicle for brand in vehicles.values() for vehicle in brand
    ]:
        vehicle_state_path = (Path("vehicles") /
                              vehicle_base["attributes"]["bodyType"] /
                              f"state_{vehicle_base['vin']}_0.json")
        vehicle_state = json.loads(
            load_fixture(
                vehicle_state_path,
                integration=BMW_DOMAIN,
            ))

        account.add_vehicle(
            vehicle_base,
            vehicle_state,
            fetched_at,
        )

        # simulate storing fingerprints
        if account.config.log_response_path:
            log_to_to_file(
                json.dumps(vehicle_state),
                account.config.log_response_path,
                f"state_{vehicle_base['vin']}",
            )
async def test_async_integration_yaml_config(hass):
    """Test loading yaml config for an integration."""
    mock_integration(hass, MockModule(DOMAIN))

    yaml_path = get_fixture_path(f"helpers/{DOMAIN}_configuration.yaml")
    with patch.object(config, "YAML_CONFIG_FILE", yaml_path):
        processed_config = await async_integration_yaml_config(hass, DOMAIN)

    assert processed_config == {DOMAIN: [{"name": "one"}, {"name": "two"}]}
Exemple #5
0
async def async_yaml_patch_helper(hass, filename):
    """Help update configuration.yaml."""
    yaml_path = get_fixture_path(filename, "template")
    with patch.object(config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()
async def test_reload_notify(hass):
    """Verify we can reload the notify service."""

    assert await async_setup_component(
        hass,
        "group",
        {},
    )
    await hass.async_block_till_done()

    assert await async_setup_component(
        hass,
        notify.DOMAIN,
        {
            notify.DOMAIN: [
                {
                    "name": "demo1",
                    "platform": "demo"
                },
                {
                    "name": "demo2",
                    "platform": "demo"
                },
                {
                    "name": "group_notify",
                    "platform": "group",
                    "services": [{
                        "service": "demo1"
                    }],
                },
            ]
        },
    )
    await hass.async_block_till_done()

    assert hass.services.has_service(notify.DOMAIN, "demo1")
    assert hass.services.has_service(notify.DOMAIN, "demo2")
    assert hass.services.has_service(notify.DOMAIN, "group_notify")

    yaml_path = get_fixture_path("configuration.yaml", "group")

    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            "group",
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert hass.services.has_service(notify.DOMAIN, "demo1")
    assert hass.services.has_service(notify.DOMAIN, "demo2")
    assert not hass.services.has_service(notify.DOMAIN, "group_notify")
    assert hass.services.has_service(notify.DOMAIN, "new_group_notify")
Exemple #7
0
async def test_reloading(hass, hass_client):
    """Test we can cleanly reload."""
    respx.get("http://example.com").respond(text="hello world")

    await async_setup_component(
        hass,
        "camera",
        {
            "camera": {
                "name": "config_test",
                "platform": "generic",
                "still_image_url": "http://example.com",
                "username": "******",
                "password": "******",
            }
        },
    )
    await hass.async_block_till_done()

    client = await hass_client()

    resp = await client.get("/api/camera_proxy/camera.config_test")

    assert resp.status == HTTPStatus.OK
    assert respx.calls.call_count == 1
    body = await resp.text()
    assert body == "hello world"

    yaml_path = get_fixture_path("configuration.yaml", "generic")

    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 1

    resp = await client.get("/api/camera_proxy/camera.config_test")

    assert resp.status == HTTPStatus.NOT_FOUND

    resp = await client.get("/api/camera_proxy/camera.reload")

    assert resp.status == HTTPStatus.OK
    assert respx.calls.call_count == 2
    body = await resp.text()
    assert body == "hello world"
async def test_setup_reload_service_with_platform_that_provides_async_reset_platform(
    hass, ):
    """Test setting up a reload service using a platform that has its own async_reset_platform."""
    component_setup = AsyncMock(return_value=True)

    setup_called = []
    async_reset_platform_called = []

    async def setup_platform(*args):
        setup_called.append(args)

    async def async_reset_platform(*args):
        async_reset_platform_called.append(args)

    mock_integration(hass, MockModule(DOMAIN, async_setup=component_setup))
    integration = await async_get_integration(hass, DOMAIN)
    integration.get_component().async_reset_platform = async_reset_platform

    mock_integration(hass, MockModule(PLATFORM, dependencies=[DOMAIN]))

    mock_platform = MockPlatform(async_setup_platform=setup_platform)
    mock_entity_platform(hass, f"{DOMAIN}.{PLATFORM}", mock_platform)

    component = EntityComponent(_LOGGER, DOMAIN, hass)

    await component.async_setup(
        {DOMAIN: {
            "platform": PLATFORM,
            "name": "xyz"
        }})
    await hass.async_block_till_done()
    assert component_setup.called

    assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
    assert len(setup_called) == 1

    await async_setup_reload_service(hass, PLATFORM, [DOMAIN])

    yaml_path = get_fixture_path("helpers/reload_configuration.yaml")
    with patch.object(config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            PLATFORM,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert len(setup_called) == 1
    assert len(async_reset_platform_called) == 1
Exemple #9
0
async def test_file_path_invalid(hass: HomeAssistant) -> None:
    """Test the File sensor with invalid path."""
    config = {
        "sensor": {
            "platform": "file",
            "name": "file4",
            "file_path": get_fixture_path("file_value.txt", "file"),
        }
    }

    with patch.object(hass.config, "is_allowed_path", return_value=False):
        assert await async_setup_component(hass, "sensor", config)
        await hass.async_block_till_done()

    assert len(hass.states.async_entity_ids("sensor")) == 0
Exemple #10
0
async def test_integration_reload(hass, caplog, mock_modbus):
    """Run test for integration reload."""

    caplog.set_level(logging.INFO)
    caplog.clear()

    yaml_path = get_fixture_path("configuration.yaml", "modbus")
    now = dt_util.utcnow()
    with mock.patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(DOMAIN, SERVICE_RELOAD, blocking=True)
        await hass.async_block_till_done()
        for i in range(4):
            now = now + timedelta(seconds=1)
            async_fire_time_changed(hass, now)
            await hass.async_block_till_done()
    assert "Modbus reloading" in caplog.text
Exemple #11
0
async def test_file_empty(hass: HomeAssistant) -> None:
    """Test the File sensor with an empty file."""
    config = {
        "sensor": {
            "platform": "file",
            "name": "file3",
            "file_path": get_fixture_path("file_empty.txt", "file"),
        }
    }

    with patch.object(hass.config, "is_allowed_path", return_value=True):
        assert await async_setup_component(hass, "sensor", config)
        await hass.async_block_till_done()

    state = hass.states.get("sensor.file3")
    assert state.state == STATE_UNKNOWN
Exemple #12
0
async def test_reload(hass):
    """Verify we can reload bayesian sensors."""

    config = {
        "binary_sensor": {
            "name":
            "test",
            "platform":
            "bayesian",
            "observations": [
                {
                    "platform": "state",
                    "entity_id": "sensor.test_monitored",
                    "to_state": "on",
                    "prob_given_true": 0.9,
                    "prob_given_false": 0.4,
                },
            ],
            "prior":
            0.2,
            "probability_threshold":
            0.32,
        }
    }

    await async_setup_component(hass, "binary_sensor", config)
    await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 1

    assert hass.states.get("binary_sensor.test")

    yaml_path = get_fixture_path("configuration.yaml", "bayesian")

    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 1

    assert hass.states.get("binary_sensor.test") is None
    assert hass.states.get("binary_sensor.test2")
Exemple #13
0
async def test_file_value_template(hass: HomeAssistant) -> None:
    """Test the File sensor with JSON entries."""
    config = {
        "sensor": {
            "platform": "file",
            "name": "file2",
            "file_path": get_fixture_path("file_value_template.txt", "file"),
            "value_template": "{{ value_json.temperature }}",
        }
    }

    with patch.object(hass.config, "is_allowed_path", return_value=True):
        assert await async_setup_component(hass, "sensor", config)
        await hass.async_block_till_done()

    state = hass.states.get("sensor.file2")
    assert state.state == "26"
async def test_reload(hass):
    """Verify we can reload."""

    respx.get("http://localhost") % HTTPStatus.OK

    assert await async_setup_component(
        hass,
        DOMAIN,
        {
            DOMAIN: [{
                "resource": "http://localhost",
                "method": "GET",
                "verify_ssl": "false",
                "timeout": 30,
                "sensor": [
                    {
                        "name": "mockrest",
                    },
                ],
            }]
        },
    )
    await hass.async_block_till_done()
    await hass.async_start()
    await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 1

    assert hass.states.get("sensor.mockrest")

    yaml_path = get_fixture_path("configuration_top_level.yaml", "rest")

    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            "rest",
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert hass.states.get("sensor.mockreset") is None
    assert hass.states.get("sensor.rollout")
    assert hass.states.get("sensor.fallover")
async def test_setup_reload_service_when_async_process_component_config_fails(
        hass):
    """Test setting up a reload service with the config processing failing."""
    component_setup = Mock(return_value=True)

    setup_called = []

    async def setup_platform(*args):
        setup_called.append(args)

    mock_integration(hass, MockModule(DOMAIN, setup=component_setup))
    mock_integration(hass, MockModule(PLATFORM, dependencies=[DOMAIN]))

    mock_platform = MockPlatform(async_setup_platform=setup_platform)
    mock_entity_platform(hass, f"{DOMAIN}.{PLATFORM}", mock_platform)

    component = EntityComponent(_LOGGER, DOMAIN, hass)

    await component.async_setup(
        {DOMAIN: {
            "platform": PLATFORM,
            "sensors": None
        }})
    await hass.async_block_till_done()
    assert component_setup.called

    assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
    assert len(setup_called) == 1

    await async_setup_reload_service(hass, PLATFORM, [DOMAIN])

    yaml_path = get_fixture_path("helpers/reload_configuration.yaml")
    with patch.object(config, "YAML_CONFIG_FILE", yaml_path), patch.object(
            config, "async_process_component_config", return_value=None):
        await hass.services.async_call(
            PLATFORM,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert len(setup_called) == 1
Exemple #16
0
async def test_reload(hass):
    """Verify we can reload history_stats sensors."""
    await async_init_recorder_component(hass)

    hass.state = ha.CoreState.not_running
    hass.states.async_set("binary_sensor.test_id", "on")

    await async_setup_component(
        hass,
        "sensor",
        {
            "sensor": {
                "platform": "history_stats",
                "entity_id": "binary_sensor.test_id",
                "name": "test",
                "state": "on",
                "start": "{{ as_timestamp(now()) - 3600 }}",
                "duration": "01:00",
            },
        },
    )
    await hass.async_block_till_done()
    await hass.async_start()
    await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 2

    assert hass.states.get("sensor.test")

    yaml_path = get_fixture_path("configuration.yaml", "history_stats")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 2

    assert hass.states.get("sensor.test") is None
    assert hass.states.get("sensor.second_test")
Exemple #17
0
async def test_reload(hass):
    """Verify we can reload filter sensors."""
    await hass.async_add_executor_job(init_recorder_component,
                                      hass)  # force in memory db

    hass.states.async_set("sensor.test_monitored", 12345)
    await async_setup_component(
        hass,
        "sensor",
        {
            "sensor": [
                {
                    "platform": "statistics",
                    "name": "test",
                    "entity_id": "sensor.test_monitored",
                    "state_characteristic": "mean",
                    "sampling_size": 100,
                },
            ]
        },
    )
    await hass.async_block_till_done()
    await hass.async_start()
    await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 2

    assert hass.states.get("sensor.test")

    yaml_path = get_fixture_path("configuration.yaml", "statistics")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 2

    assert hass.states.get("sensor.test") is None
    assert hass.states.get("sensor.cputest")
Exemple #18
0
async def test_reload(hass):
    """Test the ability to reload switches."""
    await async_setup_component(
        hass,
        SWITCH_DOMAIN,
        {
            SWITCH_DOMAIN: [
                {
                    "platform": "demo"
                },
                {
                    "platform": DOMAIN,
                    "entities": [
                        "switch.ac",
                        "switch.decorative_lights",
                    ],
                    "all": "false",
                },
            ]
        },
    )
    await hass.async_block_till_done()

    await hass.async_block_till_done()
    await hass.async_start()

    await hass.async_block_till_done()
    assert hass.states.get("switch.switch_group").state == STATE_ON

    yaml_path = get_fixture_path("configuration.yaml", "group")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert hass.states.get("switch.switch_group") is None
    assert hass.states.get("switch.master_switches_g") is not None
    assert hass.states.get("switch.outside_switches_g") is not None
async def test_reload_platform(hass):
    """Test the polling of only updated entities."""
    component_setup = Mock(return_value=True)

    setup_called = []

    async def setup_platform(*args):
        setup_called.append(args)

    mock_integration(hass, MockModule(DOMAIN, setup=component_setup))
    mock_integration(hass, MockModule(PLATFORM, dependencies=[DOMAIN]))

    mock_platform = MockPlatform(async_setup_platform=setup_platform)
    mock_entity_platform(hass, f"{DOMAIN}.{PLATFORM}", mock_platform)

    component = EntityComponent(_LOGGER, DOMAIN, hass)

    await component.async_setup(
        {DOMAIN: {
            "platform": PLATFORM,
            "sensors": None
        }})
    await hass.async_block_till_done()
    assert component_setup.called

    assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
    assert len(setup_called) == 1

    platform = async_get_platform_without_config_entry(hass, PLATFORM, DOMAIN)
    assert platform.platform_name == PLATFORM
    assert platform.domain == DOMAIN

    yaml_path = get_fixture_path("helpers/reload_configuration.yaml")
    with patch.object(config, "YAML_CONFIG_FILE", yaml_path):
        await async_reload_integration_platforms(hass, PLATFORM, [DOMAIN])

    assert len(setup_called) == 2

    existing_platforms = async_get_platforms(hass, PLATFORM)
    for existing_platform in existing_platforms:
        existing_platform.config_entry = "abc"
    assert not async_get_platform_without_config_entry(hass, PLATFORM, DOMAIN)
Exemple #20
0
async def test_reload(hass, setup_comp):
    """Test the ability to reload fans."""
    await hass.async_block_till_done()
    await hass.async_start()

    await hass.async_block_till_done()
    assert hass.states.get(FAN_GROUP).state == STATE_OFF

    yaml_path = get_fixture_path("fan_configuration.yaml", "group")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            "group",
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert hass.states.get(FAN_GROUP) is None
    assert hass.states.get("fan.upstairs_fans") is not None
async def test_reload(hass: HomeAssistant):
    """Verify we can reload statistics sensors."""
    await async_init_recorder_component(hass)

    await async_setup_component(
        hass,
        "sensor",
        {
            "sensor": [
                {
                    "platform": "statistics",
                    "name": "test",
                    "entity_id": "sensor.test_monitored",
                    "state_characteristic": "mean",
                    "sampling_size": 100,
                },
            ]
        },
    )
    await hass.async_block_till_done()

    hass.states.async_set("sensor.test_monitored", "0")
    await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 2
    assert hass.states.get("sensor.test")

    yaml_path = get_fixture_path("configuration.yaml", "statistics")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            STATISTICS_DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
    await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 2

    assert hass.states.get("sensor.test") is None
    assert hass.states.get("sensor.cputest")
Exemple #22
0
async def test_reload(hass):
    """Test the ability to reload locks."""
    await async_setup_component(
        hass,
        LOCK_DOMAIN,
        {
            LOCK_DOMAIN: [
                {
                    "platform": "demo"
                },
                {
                    "platform": DOMAIN,
                    "entities": [
                        "lock.front_door",
                        "lock.kitchen_door",
                    ],
                },
            ]
        },
    )
    await hass.async_block_till_done()

    await hass.async_block_till_done()
    await hass.async_start()

    await hass.async_block_till_done()
    assert hass.states.get("lock.lock_group").state == STATE_UNLOCKED

    yaml_path = get_fixture_path("configuration.yaml", "group")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert hass.states.get("lock.lock_group") is None
    assert hass.states.get("lock.inside_locks_g") is not None
    assert hass.states.get("lock.outside_locks_g") is not None
Exemple #23
0
async def test_reload_with_platform_not_setup(hass):
    """Test the ability to reload switches."""
    hass.states.async_set("switch.something", STATE_ON)
    await async_setup_component(
        hass,
        SWITCH_DOMAIN,
        {SWITCH_DOMAIN: [
            {
                "platform": "demo"
            },
        ]},
    )
    assert await async_setup_component(
        hass,
        "group",
        {
            "group": {
                "group_zero": {
                    "entities": "switch.something",
                    "icon": "mdi:work"
                },
            }
        },
    )
    await hass.async_block_till_done()

    yaml_path = get_fixture_path("configuration.yaml", "group")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert hass.states.get("switch.switch_group") is None
    assert hass.states.get("switch.master_switches_g") is not None
    assert hass.states.get("switch.outside_switches_g") is not None
async def test_reload_fails_to_read_configuration(hass):
    """Verify reload when configuration is missing or broken."""

    respx.get("http://localhost") % HTTPStatus.OK

    assert await async_setup_component(
        hass,
        DOMAIN,
        {
            DOMAIN: [{
                "resource": "http://localhost",
                "method": "GET",
                "verify_ssl": "false",
                "timeout": 30,
                "sensor": [
                    {
                        "name": "mockrest",
                    },
                ],
            }]
        },
    )
    await hass.async_block_till_done()
    await hass.async_start()
    await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 1

    yaml_path = get_fixture_path("configuration_invalid.notyaml", "rest")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            "rest",
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 1
Exemple #25
0
async def test_reload_notify(hass):
    """Verify we can reload the notify service."""

    with patch(
            "homeassistant.components.smtp.notify.MailNotificationService.connection_is_valid"
    ):
        assert await async_setup_component(
            hass,
            notify.DOMAIN,
            {
                notify.DOMAIN: [
                    {
                        "name": DOMAIN,
                        "platform": DOMAIN,
                        "recipient": "*****@*****.**",
                        "sender": "*****@*****.**",
                    },
                ]
            },
        )
        await hass.async_block_till_done()

    assert hass.services.has_service(notify.DOMAIN, DOMAIN)

    yaml_path = get_fixture_path("configuration.yaml", "smtp")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path), patch(
            "homeassistant.components.smtp.notify.MailNotificationService.connection_is_valid"
    ):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert not hass.services.has_service(notify.DOMAIN, DOMAIN)
    assert hass.services.has_service(notify.DOMAIN, "smtp_reloaded")
Exemple #26
0
async def test_reload(hass):
    """Verify we can reload trend sensors."""
    hass.states.async_set("sensor.test_state", 1234)

    await setup.async_setup_component(
        hass,
        "binary_sensor",
        {
            "binary_sensor": {
                "platform": "trend",
                "sensors": {
                    "test_trend_sensor": {
                        "entity_id": "sensor.test_state"
                    }
                },
            }
        },
    )
    await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 2

    assert hass.states.get("binary_sensor.test_trend_sensor")

    yaml_path = get_fixture_path("configuration.yaml", "trend")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 2

    assert hass.states.get("binary_sensor.test_trend_sensor") is None
    assert hass.states.get("binary_sensor.second_test_trend_sensor")
Exemple #27
0
async def test_reload(hass):
    """Verify we can reload filter sensors."""
    hass.states.async_set("sensor.test_1", 12345)
    hass.states.async_set("sensor.test_2", 45678)

    await async_setup_component(
        hass,
        "sensor",
        {
            "sensor": {
                "platform": "min_max",
                "name": "test",
                "type": "mean",
                "entity_ids": ["sensor.test_1", "sensor.test_2"],
            }
        },
    )
    await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 3

    assert hass.states.get("sensor.test")

    yaml_path = get_fixture_path("configuration.yaml", "min_max")

    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert len(hass.states.async_all()) == 3

    assert hass.states.get("sensor.test") is None
    assert hass.states.get("sensor.second_test")
Exemple #28
0
async def test_reload(hass):
    """Verify we can reload reset sensors."""

    respx.get("http://localhost") % HTTPStatus.OK

    await async_setup_component(
        hass,
        "binary_sensor",
        {
            "binary_sensor": {
                "platform": "rest",
                "method": "GET",
                "name": "mockrest",
                "resource": "http://localhost",
            }
        },
    )
    await hass.async_block_till_done()
    await hass.async_start()
    await hass.async_block_till_done()

    assert len(hass.states.async_all("binary_sensor")) == 1

    assert hass.states.get("binary_sensor.mockrest")

    yaml_path = get_fixture_path("configuration.yaml", "rest")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            "rest",
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert hass.states.get("binary_sensor.mockreset") is None
    assert hass.states.get("binary_sensor.rollout")
Exemple #29
0
async def test_reload_with_base_integration_platform_not_setup(hass):
    """Test the ability to reload locks."""
    assert await async_setup_component(
        hass,
        "group",
        {
            "group": {
                "group_zero": {
                    "entities": "lock.something",
                    "icon": "mdi:work"
                },
            }
        },
    )
    await hass.async_block_till_done()
    hass.states.async_set("lock.front_lock", STATE_LOCKED)
    hass.states.async_set("lock.back_lock", STATE_UNLOCKED)

    hass.states.async_set("lock.outside_lock", STATE_LOCKED)
    hass.states.async_set("lock.outside_lock_2", STATE_LOCKED)

    yaml_path = get_fixture_path("configuration.yaml", "group")
    with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
        await hass.services.async_call(
            DOMAIN,
            SERVICE_RELOAD,
            {},
            blocking=True,
        )
        await hass.async_block_till_done()

    assert hass.states.get("lock.lock_group") is None
    assert hass.states.get("lock.inside_locks_g") is not None
    assert hass.states.get("lock.outside_locks_g") is not None
    assert hass.states.get("lock.inside_locks_g").state == STATE_UNLOCKED
    assert hass.states.get("lock.outside_locks_g").state == STATE_LOCKED
Exemple #30
0
def load_fixture_binary(filename):
    """Load a binary fixture."""
    return get_fixture_path(filename, "ipp").read_bytes()