Skip to content

Commit

Permalink
Run formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 17, 2023
1 parent 3584079 commit 5ac2885
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
8 changes: 6 additions & 2 deletions custom_components/powercalc/__init__.py
Expand Up @@ -272,7 +272,9 @@ async def _create_domain_groups(event: None) -> None:
_LOGGER.debug("Setting up domain based group sensors..")
for domain in domain_groups:
if domain not in hass.data[DOMAIN].get(DATA_DOMAIN_ENTITIES):
_LOGGER.error("Cannot setup group for domain %s, no entities found", domain)
_LOGGER.error(
"Cannot setup group for domain %s, no entities found", domain

Check failure on line 276 in custom_components/powercalc/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (COM812)

custom_components/powercalc/__init__.py:276:82: COM812 Trailing comma missing
)
continue

domain_entities = hass.data[DOMAIN].get(DATA_DOMAIN_ENTITIES)[domain]
Expand All @@ -297,7 +299,9 @@ async def _create_domain_groups(event: None) -> None:
)


async def setup_yaml_sensors(hass: HomeAssistant, config: ConfigType, domain_config: ConfigType) -> None:
async def setup_yaml_sensors(
hass: HomeAssistant, config: ConfigType, domain_config: ConfigType

Check failure on line 303 in custom_components/powercalc/__init__.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (COM812)

custom_components/powercalc/__init__.py:303:71: COM812 Trailing comma missing
) -> None:
sensors: list = domain_config.get(CONF_SENSORS, [])
sorted_sensors = sorted(
sensors,
Expand Down
4 changes: 3 additions & 1 deletion custom_components/powercalc/config_flow.py
Expand Up @@ -705,7 +705,9 @@ async def async_step_power_advanced(

return self.async_show_form(
step_id="power_advanced",
data_schema=_fill_schema_defaults(SCHEMA_POWER_ADVANCED, _get_global_powercalc_config(self.hass)),
data_schema=_fill_schema_defaults(
SCHEMA_POWER_ADVANCED, _get_global_powercalc_config(self.hass)

Check failure on line 709 in custom_components/powercalc/config_flow.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (COM812)

custom_components/powercalc/config_flow.py:709:79: COM812 Trailing comma missing
),
errors={},
)

Expand Down
21 changes: 15 additions & 6 deletions custom_components/powercalc/service/gui_configuration.py
Expand Up @@ -20,21 +20,30 @@
CONF_ENERGY_INTEGRATION_METHOD,
]

SERVICE_SCHEMA = vol.Schema({
vol.Required("field"): vol.In(ALLOWED_CONFIG_KEYS),
vol.Required("value"): cv.string,
})
SERVICE_SCHEMA = vol.Schema(
{
vol.Required("field"): vol.In(ALLOWED_CONFIG_KEYS),
vol.Required("value"): cv.string,
}

Check failure on line 27 in custom_components/powercalc/service/gui_configuration.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (COM812)

custom_components/powercalc/service/gui_configuration.py:27:6: COM812 Trailing comma missing
)


@bind_hass
def change_gui_configuration(hass: HomeAssistant, call: ServiceCall) -> None:
field = call.data["field"]
value = call.data["value"]

if field in [CONF_CREATE_ENERGY_SENSOR, CONF_CREATE_UTILITY_METERS, CONF_IGNORE_UNAVAILABLE_STATE]:
if field in [
CONF_CREATE_ENERGY_SENSOR,
CONF_CREATE_UTILITY_METERS,
CONF_IGNORE_UNAVAILABLE_STATE,
]:
value = cv.boolean(value)

if field == CONF_ENERGY_INTEGRATION_METHOD and value not in ENERGY_INTEGRATION_METHODS:
if (
field == CONF_ENERGY_INTEGRATION_METHOD
and value not in ENERGY_INTEGRATION_METHODS
):
raise HomeAssistantError(f"Invalid integration method {value}")

for entry in hass.config_entries.async_entries(DOMAIN):
Expand Down
18 changes: 13 additions & 5 deletions tests/config_flow/test_virtual_power_fixed.py
Expand Up @@ -169,7 +169,9 @@ async def test_entity_selection_mandatory(hass: HomeAssistant) -> None:
assert result["errors"] == {"entity_id": "entity_mandatory"}


async def test_global_configuration_is_applied_to_field_default(hass: HomeAssistant) -> None:
async def test_global_configuration_is_applied_to_field_default(
hass: HomeAssistant,
) -> None:
"""Field should be set to match powercalc global configuration by default"""
global_config = {
CONF_CREATE_UTILITY_METERS: True,
Expand All @@ -181,7 +183,9 @@ async def test_global_configuration_is_applied_to_field_default(hass: HomeAssist
result = await select_sensor_type(hass, SensorType.VIRTUAL_POWER)
assert result["type"] == data_entry_flow.FlowResultType.FORM
schema_keys: list[vol.Optional] = list(result["data_schema"].schema.keys())
assert schema_keys[schema_keys.index(CONF_CREATE_UTILITY_METERS)].description == {"suggested_value": True}
assert schema_keys[schema_keys.index(CONF_CREATE_UTILITY_METERS)].description == {
"suggested_value": True
}

result = await hass.config_entries.flow.async_configure(
result["flow_id"],
Expand All @@ -197,6 +201,10 @@ async def test_global_configuration_is_applied_to_field_default(hass: HomeAssist
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["step_id"] == "power_advanced"
schema_keys: list[vol.Optional] = list(result["data_schema"].schema.keys())
assert schema_keys[schema_keys.index(CONF_ENERGY_INTEGRATION_METHOD)].default() == ENERGY_INTEGRATION_METHOD_RIGHT
assert schema_keys[schema_keys.index(CONF_IGNORE_UNAVAILABLE_STATE)].description == {"suggested_value": True}

assert (
schema_keys[schema_keys.index(CONF_ENERGY_INTEGRATION_METHOD)].default()
== ENERGY_INTEGRATION_METHOD_RIGHT
)
assert schema_keys[
schema_keys.index(CONF_IGNORE_UNAVAILABLE_STATE)
].description == {"suggested_value": True}
18 changes: 14 additions & 4 deletions tests/service/test_gui_configuration.py
Expand Up @@ -46,15 +46,23 @@ async def test_change_gui_configuration(hass: HomeAssistant) -> None:
await run_powercalc_setup(hass, {}, {})

await call_service(hass, CONF_IGNORE_UNAVAILABLE_STATE, "1")
await call_service(hass, CONF_ENERGY_INTEGRATION_METHOD, ENERGY_INTEGRATION_METHOD_LEFT)
await call_service(
hass, CONF_ENERGY_INTEGRATION_METHOD, ENERGY_INTEGRATION_METHOD_LEFT
)

config_entry_a = hass.config_entries.async_get_entry(config_entry_a.entry_id)
assert config_entry_a.data[CONF_IGNORE_UNAVAILABLE_STATE]
assert config_entry_a.data[CONF_ENERGY_INTEGRATION_METHOD] == ENERGY_INTEGRATION_METHOD_LEFT
assert (
config_entry_a.data[CONF_ENERGY_INTEGRATION_METHOD]
== ENERGY_INTEGRATION_METHOD_LEFT
)

config_entry_b = hass.config_entries.async_get_entry(config_entry_b.entry_id)
assert config_entry_b.data[CONF_IGNORE_UNAVAILABLE_STATE]
assert config_entry_b.data[CONF_ENERGY_INTEGRATION_METHOD] == ENERGY_INTEGRATION_METHOD_LEFT
assert (
config_entry_b.data[CONF_ENERGY_INTEGRATION_METHOD]
== ENERGY_INTEGRATION_METHOD_LEFT
)

config_entry_c = hass.config_entries.async_get_entry(config_entry_c.entry_id)
assert CONF_IGNORE_UNAVAILABLE_STATE not in config_entry_c.data
Expand All @@ -80,7 +88,9 @@ async def call_service(hass: HomeAssistant, field: str, value: str) -> None:
await hass.async_block_till_done()


def create_config_entry(entity_id: str, extra_entry_data: ConfigType) -> MockConfigEntry:
def create_config_entry(
entity_id: str, extra_entry_data: ConfigType
) -> MockConfigEntry:
unique_id = str(uuid.uuid4())
return MockConfigEntry(
domain=DOMAIN,
Expand Down

0 comments on commit 5ac2885

Please sign in to comment.