Skip to content

Remove need for separate EgardiaServer setup #11344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 28, 2017
Merged

Remove need for separate EgardiaServer setup #11344

merged 6 commits into from
Dec 28, 2017

Conversation

jeroenterheerdt
Copy link
Contributor

@jeroenterheerdt jeroenterheerdt commented Dec 28, 2017

Description:

We removed the need for the user to run a separate Egardiaserver component. This is a breaking change, but makes the usage of the component much easier (and it can now also run on HASS.io).
This is a replacement for #11322

Related issue (if applicable): fixes #

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4282

Example entry for configuration.yaml (if applicable):

alarm_control_panel:
  - platform: egardia
    host: XX.XX.XX.XX
    username: XX
    password: XX
    report_server_enabled: True
    report_server_port: 52010

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • [] New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

if self._egardiaserver is not None:
_LOGGER.debug("Starting EgardiaServer and registering callback")
# Register callback for alarm status changes through EgardiaServer
self._egardiaserver.register_callback(self.handle_system_status_event)

Choose a reason for hiding this comment

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

line too long (82 > 79 characters)

"starting EgardiaServer")
except IOError as ioe:
return False

Choose a reason for hiding this comment

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

blank line contains whitespace

bound = hass.data[DATA_EGARDIASERVER].bind()
if not bound:
raise IOError("Binding error occurred while " +
"starting EgardiaServer")

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent

_LOGGER.info("Setting up EgardiaServer")
try:
if DATA_EGARDIASERVER not in hass.data:
hass.data[DATA_EGARDIASERVER] = egardiaserver.EgardiaServer('', rs_port)

Choose a reason for hiding this comment

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

line too long (88 > 79 characters)

except requests.exceptions.RequestException:
raise exc.PlatformNotReady()
except egardiadevice.UnauthorizedError:
_LOGGER.error("Unable to authorize. Wrong password or username")
return False


if rs_enabled:

Choose a reason for hiding this comment

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

too many blank lines (2)

except requests.exceptions.RequestException:
raise exc.PlatformNotReady()
except egardiadevice.UnauthorizedError:
_LOGGER.error("Unable to authorize. Wrong password or username")
return False


Choose a reason for hiding this comment

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

blank line contains whitespace

if self._egardiaserver is not None:
_LOGGER.debug("Starting EgardiaServer and registering callback")
# Register callback for alarm status changes through EgardiaServer
self._egardiaserver.register_callback(self.handle_status_event)
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to do this inside the entity. You have access to the callback method of the entity as soon as it has been instantiated. Please move the registration and start of the server to outside the entity in setup platform. Then you don't need to pass in hass to the entity either.

"""Initialize object."""
self._name = name
self._egardiasystem = egardiasystem
self._status = STATE_UNKNOWN
self._rs_enabled = rs_enabled
Copy link
Member

Choose a reason for hiding this comment

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

Keep this.

@@ -119,23 +140,18 @@ def state(self):
@property
def should_poll(self):
"""Poll if no report server is enabled."""
if not self._rs_enabled:
Copy link
Member

Choose a reason for hiding this comment

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

Keep this.

"starting EgardiaServer")
except IOError:
return False

add_devices([EgardiaAlarm(
Copy link
Member

Choose a reason for hiding this comment

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

Separate the entity instantiation from the entity addition.

@MartinHjelmare
Copy link
Member

See my comments in the old PR about home assistant event listener for stop.

hass.data[D_EGARDIASRV].stop()

# listen to home assistant stop event
hass.bus.listen('homeassistant_stop', handle_stop_event)
Copy link
Member

Choose a reason for hiding this comment

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

Use hass.bus.listen_once and import the home assistant stop event constant from const.py and use that here.

_LOGGER.info("Setting up EgardiaServer")
try:
if D_EGARDIASRV not in hass.data:
hass.data[D_EGARDIASRV] = egardiaserver.EgardiaServer('',
Copy link
Member

Choose a reason for hiding this comment

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

Cache the server instance in a local variable so you don't need to look that up in hass.data every time.

hass.data[D_EGARDIASRV] = server = egardiaserver.EgardiaServer(...)

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Final comment I think.

hass.data[D_EGARDIASRV].register_callback(
eg_dev.handle_status_event)
hass.data[D_EGARDIASRV].start()
server.register_callback(eg_dev.handle_status_event)
Copy link
Member

Choose a reason for hiding this comment

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

Registering a callback should be done for each setup_platform run, so move that out of the check for existing server in hass.data . It shouldn't matter much if you put it after server.start().

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

setup_platform shouldn't return anything.


try:
egardiasystem = egardiadevice.EgardiaDevice(
host, port, username, password, '')
host, port, username, password, '', version)
except requests.exceptions.RequestException:
raise exc.PlatformNotReady()
except egardiadevice.UnauthorizedError:
_LOGGER.error("Unable to authorize. Wrong password or username")
return False
Copy link
Member

Choose a reason for hiding this comment

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

Just return.

hass.data[D_EGARDIASRV] = server
server.start()
except IOError:
return False
Copy link
Member

Choose a reason for hiding this comment

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

Just return.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Great!

@MartinHjelmare MartinHjelmare changed the title Removing need for separate EgardiaServer setup Remove need for separate EgardiaServer setup Dec 28, 2017
@MartinHjelmare MartinHjelmare merged commit 966ab20 into home-assistant:dev Dec 28, 2017
@jeroenterheerdt
Copy link
Contributor Author

Thanks for your help Martin!

@jeroenterheerdt jeroenterheerdt deleted the egardia branch December 31, 2017 13:03
@balloob balloob mentioned this pull request Jan 11, 2018
@home-assistant home-assistant locked and limited conversation to collaborators May 29, 2018
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