-
-
Notifications
You must be signed in to change notification settings - Fork 37.2k
Add Genie Aladdin Connect cover component #15699
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
51cc1ae
Add Genie Aladdin Connect cover component
shoejosh e11d643
Fix lines being too long
shoejosh 79c6159
Fix issues found in review
shoejosh a2f5b93
remove Unknown state, use None instead
shoejosh ee57678
Fixed requirements_all
shoejosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| """ | ||
| Platform for the Aladdin Connect cover component. | ||
|
|
||
| For more details about this platform, please refer to the documentation | ||
| https://home-assistant.io/components/cover.aladdin_connect/ | ||
| """ | ||
| import logging | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components.cover import (CoverDevice, PLATFORM_SCHEMA, | ||
| SUPPORT_OPEN, SUPPORT_CLOSE) | ||
| from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, STATE_CLOSED, | ||
| STATE_OPENING, STATE_CLOSING, STATE_OPEN) | ||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
| REQUIREMENTS = ['aladdin_connect==0.1'] | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| NOTIFICATION_ID = 'aladdin_notification' | ||
| NOTIFICATION_TITLE = 'Aladdin Connect Cover Setup' | ||
|
|
||
| STATES_MAP = { | ||
| 'open': STATE_OPEN, | ||
| 'opening': STATE_OPENING, | ||
| 'closed': STATE_CLOSED, | ||
| 'closing': STATE_CLOSING | ||
| } | ||
|
|
||
| SUPPORTED_FEATURES = SUPPORT_OPEN | SUPPORT_CLOSE | ||
|
|
||
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Required(CONF_USERNAME): cv.string, | ||
| vol.Required(CONF_PASSWORD): cv.string | ||
| }) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_devices, discovery_info=None): | ||
| """Set up the Aladdin Connect platform.""" | ||
| from aladdin_connect import AladdinConnectClient | ||
|
|
||
| username = config.get(CONF_USERNAME) | ||
| password = config.get(CONF_PASSWORD) | ||
| acc = AladdinConnectClient(username, password) | ||
|
|
||
| try: | ||
| if not acc.login(): | ||
| raise ValueError("Username or Password is incorrect") | ||
| add_devices(AladdinDevice(acc, door) for door in acc.get_doors()) | ||
| 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) | ||
|
|
||
|
|
||
| class AladdinDevice(CoverDevice): | ||
| """Representation of Aladdin Connect cover.""" | ||
|
|
||
| def __init__(self, acc, device): | ||
| """Initialize the cover.""" | ||
| self._acc = acc | ||
| self._device_id = device['device_id'] | ||
| self._number = device['door_number'] | ||
| self._name = device['name'] | ||
| self._status = STATES_MAP.get(device['status']) | ||
|
|
||
| @property | ||
| def device_class(self): | ||
| """Define this cover as a garage door.""" | ||
| return 'garage' | ||
|
|
||
| @property | ||
| def supported_features(self): | ||
| """Flag supported features.""" | ||
| return SUPPORTED_FEATURES | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the garage door.""" | ||
| return self._name | ||
|
|
||
| @property | ||
| def is_opening(self): | ||
| """Return if the cover is opening or not.""" | ||
| return self._status == STATE_OPENING | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
|
|
||
| @property | ||
| def is_closing(self): | ||
| """Return if the cover is closing or not.""" | ||
| return self._status == STATE_CLOSING | ||
|
|
||
| @property | ||
| def is_closed(self): | ||
| """Return None if status is unknown, True if closed, else False.""" | ||
| if self._status is None: | ||
| return None | ||
| return self._status == STATE_CLOSED | ||
|
|
||
| def close_cover(self, **kwargs): | ||
| """Issue close command to cover.""" | ||
| self._acc.close_door(self._device_id, self._number) | ||
|
|
||
| def open_cover(self, **kwargs): | ||
| """Issue open command to cover.""" | ||
| self._acc.open_door(self._device_id, self._number) | ||
|
|
||
| def update(self): | ||
| """Update status of cover.""" | ||
| acc_status = self._acc.get_door_status(self._device_id, self._number) | ||
| self._status = STATES_MAP.get(acc_status) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.