Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix model.json file not found errors #1045

Merged
merged 1 commit into from Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -33,7 +33,7 @@ async def get_power_profile(
manufacturer = config.get(CONF_MANUFACTURER) or model_info.manufacturer
model = config.get(CONF_MODEL) or model_info.model

if manufacturer is None or model is None:
if not manufacturer or not model:
return None

custom_model_directory = config.get(CONF_CUSTOM_MODEL_DIRECTORY)
Expand Down
18 changes: 17 additions & 1 deletion tests/power_profile/test_model_discovery.py
@@ -1,8 +1,9 @@
import logging

import pytest
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_registry import EntityRegistry

from custom_components.powercalc.const import DOMAIN
from custom_components.powercalc.power_profile.model_discovery import (
autodiscover_model,
get_power_profile,
Expand Down Expand Up @@ -75,3 +76,18 @@ async def test_autodiscover_model_from_entity_entry(

assert model_info.manufacturer == expected_manufacturer
assert model_info.model == expected_model


async def test_get_power_profile_empty_manufacturer(hass: HomeAssistant, entity_reg: EntityRegistry, caplog: pytest.LogCaptureFixture):
caplog.set_level(logging.ERROR)
light_mock = MockLight("test")
light_mock.manufacturer = ""
light_mock.model = "some model"

await create_mock_light_entity(hass, light_mock)

entity_entry = entity_reg.async_get("light.test")

profile = await get_power_profile(hass, {}, entity_entry)
assert not profile
assert not caplog.records