Skip to content

Commit

Permalink
Achieve 100% code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Aug 9, 2023
1 parent 9e22343 commit 1c91d8e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/test_common.py
@@ -0,0 +1,52 @@
import pytest
from homeassistant.const import CONF_ENTITY_ID, CONF_NAME
from homeassistant.core import HomeAssistant

from custom_components.powercalc import CONF_CREATE_ENERGY_SENSORS, CONF_CREATE_UTILITY_METERS
from custom_components.powercalc.common import get_merged_sensor_configuration
from custom_components.powercalc.const import CONF_CREATE_ENERGY_SENSOR


@pytest.mark.parametrize(
"configs,output_config",
[
(
[
{
CONF_CREATE_UTILITY_METERS: True,
CONF_CREATE_ENERGY_SENSORS: False,
},
{
CONF_ENTITY_ID: "switch.test",
CONF_CREATE_UTILITY_METERS: False,
},
],
{
CONF_ENTITY_ID: "switch.test",
CONF_CREATE_ENERGY_SENSORS: False,
CONF_CREATE_ENERGY_SENSOR: False,
CONF_CREATE_UTILITY_METERS: False,
},
),
(
[
{
CONF_NAME: "foo",
},
{
CONF_ENTITY_ID: "switch.test",
},
],
{
CONF_ENTITY_ID: "switch.test",
CONF_CREATE_ENERGY_SENSOR: None,
},
),
],
)
async def test_merge_configuration(
hass: HomeAssistant,
configs: list[dict],
output_config: dict,
) -> None:
assert get_merged_sensor_configuration(*configs) == output_config

0 comments on commit 1c91d8e

Please sign in to comment.