Skip to content

Move core service from core to components#5787

Merged
balloob merged 8 commits intohome-assistant:devfrom
pvizeli:core_move_service
Feb 8, 2017
Merged

Move core service from core to components#5787
balloob merged 8 commits intohome-assistant:devfrom
pvizeli:core_move_service

Conversation

@pvizeli
Copy link
Copy Markdown
Member

@pvizeli pvizeli commented Feb 7, 2017

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_config to run config Validation.

CC @balloob

  • move unittests

@mention-bot
Copy link
Copy Markdown

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "not restarting" part might no longer be relevant as there is a separate service to just check the config.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more users of those handlers: Sigterm, KeyboardInterrupt

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I call now the service.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also _async_restart_handler for sighup :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change the handling of that see on comment.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think such a dependency is a hack.
homeassistant.config shouldn't depend on homeassistant.components.*

Copy link
Copy Markdown
Member Author

@pvizeli pvizeli Feb 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depense will exists without I Import this or not... Bootstrap work in same way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LIke in homeassistant.core you call a service and not call homeassistant.components.stop()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so I propose not to import anything and just use strings to call the service.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means there can be 2 notifications Icheck, restart) meaning the same thing.
I think we should use the same ID.

@pvizeli
Copy link
Copy Markdown
Member Author

pvizeli commented Feb 7, 2017

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.

@andrey-git
Copy link
Copy Markdown
Contributor

I think SIGHUP we should also check that config is valid - otherwise the service will just go down.

@pvizeli
Copy link
Copy Markdown
Member Author

pvizeli commented Feb 7, 2017

On most posix system with systemd will kill the hole hass if SIGHUP do nothing. I think a Administrator on console have a reason do to some things and he have the possibility to check self.

@robbiet480 robbiet480 changed the title Move core servcie from core to components Move core service from core to components Feb 7, 2017
self.loop.stop()

@callback
def async_stop_handler(self, *args):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename these to async_stop() and take 0 arguments.

Will need to update the signal handlers to properly wrap the call.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, async_stop already exists. Well, in that case can we move assigning exit_code into that method and remove async_stop_handler completely?

self.loop.create_task(self.async_stop())

@callback
def async_restart_handler(self, *args):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should also extract the signal handling of the core.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, make a new PR for that

@balloob
Copy link
Copy Markdown
Member

balloob commented Feb 8, 2017

Nice 🐬

@balloob balloob merged commit 3f82ef6 into home-assistant:dev Feb 8, 2017
@home-assistant home-assistant locked and limited conversation to collaborators May 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants