-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Added gogogate2 cover #13467
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
Added gogogate2 cover #13467
Changes from 1 commit
b1e0715
9408408
4f80a55
7c03e0a
37c1500
e52f2c0
a1c844a
381a8d6
403d3af
fa51dfd
2cdf95d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| """ | ||
| Support for Gogogate2 Garage Doors. | ||
|
|
||
| For more details about this platform, please refer to the documentation | ||
| https://home-assistant.io/components/cover.gogogate2/ | ||
| """ | ||
| import logging | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components.cover import CoverDevice | ||
| from homeassistant.const import ( | ||
| CONF_USERNAME, CONF_PASSWORD, STATE_CLOSED, CONF_IP_ADDRESS, CONF_API_KEY) | ||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
| REQUIREMENTS = ['pygogogate2==0.0.2'] | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| DEFAULT_NAME = 'gogogate2' | ||
|
|
||
| NOTIFICATION_ID = 'gogogate2_notification' | ||
| NOTIFICATION_TITLE = 'Gogogate2 Cover Setup' | ||
|
|
||
| COVER_SCHEMA = vol.Schema({ | ||
| 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, | ||
| }) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Set up the Gogogate2 component.""" | ||
| from pygogogate2 import Gogogate2API as pygogogate2 | ||
|
|
||
| username = config.get(CONF_USERNAME) | ||
| password = config.get(CONF_PASSWORD) | ||
| ip_address = config.get(CONF_IP_ADDRESS) | ||
| api_key = config.get(CONF_API_KEY) | ||
| mygogogate2 = pygogogate2(username, password, ip_address, api_key) | ||
|
|
||
| try: | ||
| devices = mygogogate2.get_devices() | ||
| if devices == False: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:' |
||
| raise ValueError("Username or Password is incorrect or no devices found") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (85 > 79 characters) |
||
|
|
||
| add_devices(MyGogogate2Device(mygogogate2, door) for door in devices) | ||
| return True | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simply return. It's not checked.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed True |
||
|
|
||
| except (TypeError, KeyError, NameError, ValueError) as ex: | ||
| _LOGGER.error("%s", ex) | ||
| hass.components.persistent_notification.create( | ||
| 'Error: {}<br />' | ||
| 'You will need to restart hass after fixing.' | ||
| ''.format(ex), | ||
| title=NOTIFICATION_TITLE, | ||
| notification_id=NOTIFICATION_ID) | ||
| return False | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simply return. It's not checked.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed False |
||
|
|
||
|
|
||
| class MyGogogate2Device(CoverDevice): | ||
| """Representation of a Gogogate2 cover.""" | ||
|
|
||
| def __init__(self, mygogogate2, device): | ||
| """Initialize with API object, device id.""" | ||
| self.mygogogate2 = mygogogate2 | ||
| self.device_id = device['door'] | ||
| self._name = device['name'] | ||
| self._status = STATE_CLOSED | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let the device set the current state.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the default.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed overridden property |
||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the garage door if any.""" | ||
| return self._name if self._name else DEFAULT_NAME | ||
|
|
||
| @property | ||
| def is_closed(self): | ||
| """Return true if cover is closed, else False.""" | ||
| return self._status == STATE_CLOSED | ||
|
|
||
| def close_cover(self, **kwargs): | ||
| """Issue close command to cover.""" | ||
| self.mygogogate2.close_device(self.device_id) | ||
| self.schedule_update_ha_state(True) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
|
||
| def update(self): | ||
| """Update status of cover.""" | ||
| self._status = self.mygogogate2.get_status(self.device_id) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Caught exception and set state to STATE_UNAVAILABLE |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
CONF_NAMEto allow the user to overwrite the name of the device. Set the default toDEFAULT_NAME.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added DEFAULT_NAME