Skip to content

Added gogogate2 cover#13467

Merged
fabaff merged 11 commits intohome-assistant:devfrom
dlbroadfoot:gogogate2
Apr 6, 2018
Merged

Added gogogate2 cover#13467
fabaff merged 11 commits intohome-assistant:devfrom
dlbroadfoot:gogogate2

Conversation

@dlbroadfoot
Copy link
Copy Markdown
Contributor

@dlbroadfoot dlbroadfoot commented Mar 26, 2018

Description:

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

Example entry for configuration.yaml (if applicable):

cover:
  - platform: gogogate2
    username: email@email.com
    password: password
    ip_address: 192.168.1.200

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

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

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

  • 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:

  • Tests have been added to verify that the new code works.

@dlbroadfoot dlbroadfoot requested a review from andrey-git as a code owner March 26, 2018 10:13
@homeassistant
Copy link
Copy Markdown
Contributor

Hi @dlbroadfoot,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

try:
devices = mygogogate2.get_devices()
if devices == False:
raise ValueError("Username or Password is incorrect or no devices found")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (85 > 79 characters)


try:
devices = mygogogate2.get_devices()
if devices == False:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

comparison to False should be 'if cond is False:' or 'if not cond:'

vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_IP_ADDRESS): cv.string,
vol.Optional(CONF_API_KEY): cv.string,
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.

Please add CONF_NAME to allow the user to overwrite the name of the device. Set the default to DEFAULT_NAME.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added DEFAULT_NAME

"Username or Password is incorrect or no devices found")

add_devices(MyGogogate2Device(mygogogate2, door) for door in devices)
return True
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.

Simply return. It's not checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed True

''.format(ex),
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID)
return False
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.

Simply return. It's not checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed False

self.mygogogate2 = mygogogate2
self.device_id = device['door']
self._name = device['name']
self._status = STATE_CLOSED
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.

Let the device set the current state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Set state from device

@property
def should_poll(self):
"""Poll for state."""
return True
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.

This is the default.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed overridden property


def update(self):
"""Update status of cover."""
self._status = self.mygogogate2.get_status(self.device_id)
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 guess that there will be an exception if the device is offline.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Caught exception and set state to STATE_UNAVAILABLE

raise ValueError(
"Username or Password is incorrect or no devices found")

add_devices(MyGogogate2Device(mygogogate2, door, name) for door in devices)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

@dlbroadfoot
Copy link
Copy Markdown
Contributor Author

Hi @fabaff , I don't want to rush you but just wanted to check if you require me to do anything else before you want to review this again.

Thanks

@home-assistant home-assistant deleted a comment from houndci-bot Apr 6, 2018
@home-assistant home-assistant deleted a comment from houndci-bot Apr 6, 2018
@home-assistant home-assistant deleted a comment from houndci-bot Apr 6, 2018
_LOGGER.error("%s", ex)
self._status = STATE_UNKNOWN
self.available = False

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blank line at end of file
blank line contains whitespace

def available(self):
"""Could the device be accessed during the last update call."""
return self.available

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

blank line contains whitespace

Copy link
Copy Markdown
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

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

Thanks 🐦

@fabaff fabaff merged commit bd51143 into home-assistant:dev Apr 6, 2018
@home-assistant home-assistant deleted a comment from houndci-bot Apr 6, 2018
Copy link
Copy Markdown
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.

Commenting for future improvement.


add_devices(MyGogogate2Device(
mygogogate2, door, name) for door in devices)
return
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.

Not needed return.

''.format(ex),
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID)
return
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 as above.

self.device_id = device['door']
self._name = name or device['name']
self._status = device['status']
self.available = None
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.

This should be made private.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@fabaff, @MartinHjelmare is correct. I just tried this out and this line currently throws an error 'can't set attribute'. I've changed it to private and will submit a new PR, along with the rest of Martin's suggestions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

New PR here: #13728

Thanks

def close_cover(self, **kwargs):
"""Issue close command to cover."""
self.mygogogate2.close_device(self.device_id)
self.schedule_update_ha_state(True)
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.

Remove this. Since this is a polling entity, the state will be updated directly after the service call.

def open_cover(self, **kwargs):
"""Issue open command to cover."""
self.mygogogate2.open_device(self.device_id)
self.schedule_update_ha_state(True)
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 as above.

self.available = True
except (TypeError, KeyError, NameError, ValueError) as ex:
_LOGGER.error("%s", ex)
self._status = STATE_UNKNOWN
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.

Don't use STATE_UNKNOWN, just set the state to None.

@balloob balloob mentioned this pull request Apr 13, 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