Skip to content

Commit

Permalink
fix all erronous none entries are removed because of previous bug in …
Browse files Browse the repository at this point in the history
…Powercalc (#2295)

* fix all erronous none entries are removed because of previous bug in Powercalc

* poetry updates

* ruff fixes

* fix: mypy

* fix: mypy
  • Loading branch information
bramstroker committed Jun 11, 2024
1 parent 861ff3d commit 5e2b622
Show file tree
Hide file tree
Showing 5 changed files with 395 additions and 538 deletions.
6 changes: 5 additions & 1 deletion custom_components/powercalc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import asyncio
import logging
import random
import time

import homeassistant.helpers.config_validation as cv
import homeassistant.helpers.entity_registry as er
Expand Down Expand Up @@ -451,12 +453,14 @@ async def repair_none_config_entries_issue(hass: HomeAssistant) -> None:
for entity in entities:
entity_registry.async_remove(entity.entity_id)
try:
unique_id = f"{int(time.time() * 1000)}_{random.randint(1000, 9999)}"
object.__setattr__(entry, "unique_id", unique_id)
hass.config_entries._entries._index_entry(entry) # noqa
await hass.config_entries.async_remove(entry.entry_id)
except Exception as e: # noqa: BLE001
_LOGGER.error("problem while cleaning up None entities", exc_info=e)



def _notify_message(
hass: HomeAssistant,
notification_id: str,
Expand Down
12 changes: 6 additions & 6 deletions custom_components/powercalc/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ async def async_step_daily_energy(
self.sensor_config.update(_build_daily_energy_config(user_input, schema))
if self.sensor_config.get(CONF_CREATE_UTILITY_METERS):
return await self.async_step_utility_meter_options()
return self.create_config_entry()
return self.create_config_entry() # type: ignore

return self.async_show_form(
step_id="daily_energy",
Expand All @@ -467,7 +467,7 @@ async def async_step_group(
if not errors:
if self.sensor_config.get(CONF_CREATE_UTILITY_METERS):
return await self.async_step_utility_meter_options()
return self.create_config_entry()
return self.create_config_entry() # type: ignore

group_schema = SCHEMA_GROUP.extend(
_create_group_options_schema(self.hass).schema,
Expand Down Expand Up @@ -622,7 +622,7 @@ async def async_step_real_power(
self.sensor_config.update(user_input)
if self.sensor_config.get(CONF_CREATE_UTILITY_METERS):
return await self.async_step_utility_meter_options()
return self.create_config_entry()
return self.create_config_entry() # type: ignore

return self.async_show_form(
step_id="real_power",
Expand Down Expand Up @@ -728,7 +728,7 @@ async def async_step_power_advanced(
) -> ConfigFlowResult:
if user_input is not None or self.skip_advanced_step:
self.sensor_config.update(user_input or {})
return self.create_config_entry()
return self.create_config_entry() # type: ignore

return self.async_show_form(
step_id="power_advanced",
Expand All @@ -745,7 +745,7 @@ async def async_step_utility_meter_options(
) -> ConfigFlowResult:
if user_input is not None:
self.sensor_config.update(user_input or {})
return self.create_config_entry()
return self.create_config_entry() # type: ignore

return self.async_show_form(
step_id="utility_meter_options",
Expand Down Expand Up @@ -787,7 +787,7 @@ def create_config_entry(self) -> ConfigFlowResult:
if self.source_entity_id:
self.sensor_config.update({CONF_ENTITY_ID: self.source_entity_id})

return self.async_create_entry(title=self.name, data=self.sensor_config) # type: ignore
return self.async_create_entry(title=str(self.name), data=self.sensor_config)


class OptionsFlowHandler(OptionsFlow):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/powercalc/sensors/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def create_energy_sensor(
real_energy_sensor.entity_id,
power_sensor.entity_id,
)
return real_energy_sensor
return real_energy_sensor # type: ignore
_LOGGER.debug(
"No existing energy sensor found for the power sensor '%s'",
power_sensor.entity_id,
Expand Down
Loading

0 comments on commit 5e2b622

Please sign in to comment.