Skip to content
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

Add UpCloud platform #12011

Merged
merged 5 commits into from
Feb 28, 2018
Merged

Add UpCloud platform #12011

merged 5 commits into from
Feb 28, 2018

Conversation

scop
Copy link
Member

@scop scop commented Jan 28, 2018

Description:

Add UpCloud platform.

Related issue (if applicable): fixes #

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

Example entry for configuration.yaml (if applicable):

upcloud:
  username: YOUR_API_USERNAME
  password: YOUR_API_PASSWORD

binary_sensor:
  - platform: upcloud
    servers:
      - 002167b7-4cb1-44b7-869f-e0900ddeeae1
      - 00886296-6137-4074-afe3-068e16d89d00

switch:
  - platform: upcloud
    servers:
      - 002167b7-4cb1-44b7-869f-e0900ddeeae1
      - 00886296-6137-4074-afe3-068e16d89d00

Checklist:

  • The code change is tested and works locally.

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.

Copy link
Contributor

@dgomes dgomes left a comment

Choose a reason for hiding this comment

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

Great work! 👍

Not an official reviewer, but leave you some food for thought

return False

hass.data[DATA_UPCLOUD] = UpCloud(manager)
hass.data[DATA_UPCLOUD].update()
Copy link
Contributor

Choose a reason for hiding this comment

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

Calling update() here will delay HA launch
Can you find away around it ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure. In cases where there are only switches or binary sensors configured, this update() could just be removed, the component will call it whenever it needs to refresh. But when there are both switches and binary sensors configured, one of them will end up being configured without the data (because of the throttling) on start and thus shows incorrect/missing data.

Copy link
Contributor

@dgomes dgomes Feb 2, 2018

Choose a reason for hiding this comment

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

Looking closer, the UpCloud object is shared by both switches and binary sensors, so the servers list (which is the only thing in update()) will be shared.

But what about using homeassistant.helpers.dispatcher ?

return False

hass.data[DATA_UPCLOUD] = UpCloud(manager)
hass.data[DATA_UPCLOUD].update()
Copy link
Contributor

@dgomes dgomes Feb 2, 2018

Choose a reason for hiding this comment

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

Looking closer, the UpCloud object is shared by both switches and binary sensors, so the servers list (which is the only thing in update()) will be shared.

But what about using homeassistant.helpers.dispatcher ?

@scop
Copy link
Member Author

scop commented Feb 25, 2018

Converted to Entity, use helpers.dispatcher. Maybe ready for inclusion now?

@balloob balloob merged commit bbd58d7 into home-assistant:dev Feb 28, 2018
@balloob
Copy link
Member

balloob commented Feb 28, 2018

Awesome 🎉

try:
return STATE_MAP.get(self.data.state, STATE_UNKNOWN)
except AttributeError:
return STATE_UNKNOWN
Copy link
Member

Choose a reason for hiding this comment

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

Don't use STATE_UNKNOWN. Return None if state is not known.


def _update_callback(self):
"""Call update method."""
self.schedule_update_ha_state(True)
Copy link
Member

Choose a reason for hiding this comment

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

This could be made async by using async_schedule_update_ha_state.

async_dispatcher_connect(
self.hass, SIGNAL_UPDATE_UPCLOUD, self._update_callback)

def _update_callback(self):
Copy link
Member

Choose a reason for hiding this comment

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

This could be made async by annotating the method with @callback from core.py.


def __init__(self, upcloud, uuid):
"""Initialize a new UpCloud server switch."""
UpCloudServerEntity.__init__(self, upcloud, uuid)
Copy link
Member

Choose a reason for hiding this comment

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

super().__init__(upcloud, uuid)


def __init__(self, upcloud, uuid):
"""Initialize a new UpCloud sensor."""
UpCloudServerEntity.__init__(self, upcloud, uuid)
Copy link
Member

Choose a reason for hiding this comment

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

super().__init__(upcloud, uuid)

@scop scop deleted the upcloud-platform branch March 2, 2018 06:36
@scop scop mentioned this pull request Mar 2, 2018
1 task
@scop
Copy link
Member Author

scop commented Mar 2, 2018

Review comments addressed in #12835. Making the suggested constructor changes would have provoked pylint warnings, so I removed them altogether.

@balloob balloob mentioned this pull request Mar 9, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 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