Repository: bramstroker/homeassistant-powercalc

Issue:
dont create an EntityComponent for sensor
Hi Bram,

Ive been debuggin some difficult to find issues in Core currently, (more specific on the homeassistant.update_entity service, which errors out) and as it turns out it is caused by Powercalc, more specifically:

```
File "/config/custom_components/powercalc/__init__.py", line 223, in create_domain_groups
    component = EntityComponent(_LOGGER, SENSOR_DOMAIN, hass)
```

as Erik Montnemery put it: This is what powercalc does, and it's 100% wrong. And

> he can't create an EntityComponent for sensor
> that's done automatically by core for any integration which has sensor platforms already


Ive just been able to confirm the proper behavior of the homeassistant.update_entity service without Powercalc installed.
This is a very serious flaw in the system, interfering with core performance. Ive been forced to take out Powercalc now, to restore core functionality

please check that ?

full section in the homeassitant log:
```
2022-04-29 14:40:08 ERROR (MainThread) [custom_components.sensor] EntityComponent() called for sensor domain from
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 203, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 191, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 119, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 629, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 596, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1890, in _run_once
    handle._run()
  File "/usr/local/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/config/custom_components/powercalc/__init__.py", line 153, in _create_domain_groups
    await create_domain_groups(
  File "/config/custom_components/powercalc/__init__.py", line 223, in create_domain_groups
    component = EntityComponent(_LOGGER, SENSOR_DOMAIN, hass)
```
thanks!


Discussion:
@Mariusthvdb I'm sorry it took you some time to find the culprit. 
That makes sense. I will resolve asap, possibly tonight.

Resolving patch:
diff --git a/custom_components/powercalc/__init__.py b/custom_components/powercalc/__init__.py
--- a/custom_components/powercalc/__init__.py
+++ b/custom_components/powercalc/__init__.py
@@ -220,7 +220,7 @@ async def create_domain_groups(
     hass: HomeAssistantType, global_config: dict, domains: list[str]
 ):
     """Create group sensors aggregating all power sensors from given domains"""
-    component = EntityComponent(_LOGGER, SENSOR_DOMAIN, hass)
+    sensor_component = hass.data[SENSOR_DOMAIN]
     sensor_config = global_config.copy()
     _LOGGER.debug(f"Setting up domain based group sensors..")
     for domain in domains:
@@ -235,5 +235,5 @@ async def create_domain_groups(
         entities = await create_group_sensors(
             group_name, sensor_config, domain_entities, hass
         )
-        await component.async_add_entities(entities)
+        await sensor_component.async_add_entities(entities)
     return []


Test patch: