Added gogogate2 cover#13467
Conversation
|
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") |
There was a problem hiding this comment.
line too long (85 > 79 characters)
|
|
||
| try: | ||
| devices = mygogogate2.get_devices() | ||
| if devices == False: |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Please add CONF_NAME to allow the user to overwrite the name of the device. Set the default to DEFAULT_NAME.
There was a problem hiding this comment.
Added DEFAULT_NAME
| "Username or Password is incorrect or no devices found") | ||
|
|
||
| add_devices(MyGogogate2Device(mygogogate2, door) for door in devices) | ||
| return True |
| ''.format(ex), | ||
| title=NOTIFICATION_TITLE, | ||
| notification_id=NOTIFICATION_ID) | ||
| return False |
| self.mygogogate2 = mygogogate2 | ||
| self.device_id = device['door'] | ||
| self._name = device['name'] | ||
| self._status = STATE_CLOSED |
There was a problem hiding this comment.
Let the device set the current state.
There was a problem hiding this comment.
Set state from device
| @property | ||
| def should_poll(self): | ||
| """Poll for state.""" | ||
| return True |
There was a problem hiding this comment.
Removed overridden property
|
|
||
| def update(self): | ||
| """Update status of cover.""" | ||
| self._status = self.mygogogate2.get_status(self.device_id) |
There was a problem hiding this comment.
I guess that there will be an exception if the device is offline.
There was a problem hiding this comment.
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) |
|
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 |
| _LOGGER.error("%s", ex) | ||
| self._status = STATE_UNKNOWN | ||
| self.available = False | ||
|
|
There was a problem hiding this comment.
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 | ||
|
|
MartinHjelmare
left a comment
There was a problem hiding this comment.
Commenting for future improvement.
|
|
||
| add_devices(MyGogogate2Device( | ||
| mygogogate2, door, name) for door in devices) | ||
| return |
| ''.format(ex), | ||
| title=NOTIFICATION_TITLE, | ||
| notification_id=NOTIFICATION_ID) | ||
| return |
| self.device_id = device['door'] | ||
| self._name = name or device['name'] | ||
| self._status = device['status'] | ||
| self.available = None |
There was a problem hiding this comment.
This should be made private.
There was a problem hiding this comment.
@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.
| def close_cover(self, **kwargs): | ||
| """Issue close command to cover.""" | ||
| self.mygogogate2.close_device(self.device_id) | ||
| self.schedule_update_ha_state(True) |
There was a problem hiding this comment.
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) |
| self.available = True | ||
| except (TypeError, KeyError, NameError, ValueError) as ex: | ||
| _LOGGER.error("%s", ex) | ||
| self._status = STATE_UNKNOWN |
There was a problem hiding this comment.
Don't use STATE_UNKNOWN, just set the state to None.
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):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: