Move core service from core to components#5787
Conversation
|
@pvizeli, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabaff and @fabianhjr to be potential reviewers. |
eacfc6d to
0b89da8
Compare
homeassistant/config.py
Outdated
There was a problem hiding this comment.
The "not restarting" part might no longer be relevant as there is a separate service to just check the config.
homeassistant/core.py
Outdated
There was a problem hiding this comment.
There are more users of those handlers: Sigterm, KeyboardInterrupt
There was a problem hiding this comment.
Done. I call now the service.
There was a problem hiding this comment.
Also _async_restart_handler for sighup :)
There was a problem hiding this comment.
I change the handling of that see on comment.
homeassistant/config.py
Outdated
There was a problem hiding this comment.
I think such a dependency is a hack.
homeassistant.config shouldn't depend on homeassistant.components.*
There was a problem hiding this comment.
This depense will exists without I Import this or not... Bootstrap work in same way.
There was a problem hiding this comment.
We could call persistence notification service then there will be no dependency - i.e. hass would still come up if homeassistant.components.persistent_notification was removed.
There was a problem hiding this comment.
LIke in homeassistant.core you call a service and not call homeassistant.components.stop()
There was a problem hiding this comment.
I think it will become the same if I import this or I need to do: from ...persistent_notification Import DOMAIN, SERVICE_XY for calling the service later.
There was a problem hiding this comment.
Yes, so I propose not to import anything and just use strings to call the service.
There was a problem hiding this comment.
It's a hack but one that we use in other places in this file too, see line 31. However, line 31 does execute it a bit more classy, as it allows for people to overwrite that component.
I prefer to use the function over spelling out the service, because that's the suggested way for Python code.
fc09ecc to
9201812
Compare
homeassistant/components/__init__.py
Outdated
There was a problem hiding this comment.
This means there can be 2 notifications Icheck, restart) meaning the same thing.
I think we should use the same ID.
9201812 to
e1f57e7
Compare
|
I merge only the Service for start/restart into components. The function is used also by signal handler and other deep core stuff. It make no sense to move this core stuff also into component. |
|
I think SIGHUP we should also check that config is valid - otherwise the service will just go down. |
|
On most posix system with systemd will kill the hole hass if |
60a727c to
385c2e3
Compare
fb54834 to
6ebca2b
Compare
6ebca2b to
6a31ee8
Compare
homeassistant/core.py
Outdated
| self.loop.stop() | ||
|
|
||
| @callback | ||
| def async_stop_handler(self, *args): |
There was a problem hiding this comment.
Can we rename these to async_stop() and take 0 arguments.
Will need to update the signal handlers to properly wrap the call.
There was a problem hiding this comment.
Oh, async_stop already exists. Well, in that case can we move assigning exit_code into that method and remove async_stop_handler completely?
homeassistant/core.py
Outdated
| self.loop.create_task(self.async_stop()) | ||
|
|
||
| @callback | ||
| def async_restart_handler(self, *args): |
There was a problem hiding this comment.
We should rename this to async_restart:
def async_restart(self):
self.exit_code = RESTART_EXIT_CODE
return self.async_stop()And if we default exit_code to 0, async_stop doesn't have to assign anything.
| self.services.async_register( | ||
| DOMAIN, SERVICE_HOMEASSISTANT_RESTART, self._async_restart_handler) | ||
|
|
||
| # Setup signal handling |
There was a problem hiding this comment.
I think that we should also extract the signal handling of the core.
There was a problem hiding this comment.
Yeah, make a new PR for that
|
Nice 🐬 |
Description:
That split core Service to components like discus on #5609. I think that is the core clean variant.
I copy the good work from @andrey-git and change the handling of that PR.
I add also a new Service
check_configto run config Validation.CC @balloob