-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Adding ryobi garage door opener #14618
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bade46d
Initial component for Ryobi cover
guillaume1410 369ee94
Initial component for Ryobi cover
guillaume1410 58ecc01
Adding Ryobi cover
guillaume1410 7faf15f
Adding Ryobi cover
guillaume1410 0bc782f
Adding Ryobi cover
guillaume1410 d62077b
Minor changes
fabaff 4b22308
Remove import
fabaff 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 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 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,103 @@ | ||
""" | ||
Ryobi platform for the cover component. | ||
|
||
For more details about this platform, please refer to the documentation | ||
https://home-assistant.io/components/cover.ryobi_gdo/ | ||
""" | ||
import logging | ||
import voluptuous as vol | ||
|
||
import homeassistant.helpers.config_validation as cv | ||
|
||
from homeassistant.components.cover import ( | ||
CoverDevice, PLATFORM_SCHEMA, SUPPORT_OPEN, SUPPORT_CLOSE) | ||
from homeassistant.const import ( | ||
CONF_USERNAME, CONF_PASSWORD, STATE_UNKNOWN, STATE_CLOSED) | ||
|
||
REQUIREMENTS = ['py_ryobi_gdo==0.0.10'] | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
CONF_DEVICE_ID = 'device_id' | ||
|
||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
vol.Required(CONF_DEVICE_ID): vol.All(cv.ensure_list, [cv.string]), | ||
vol.Required(CONF_PASSWORD): cv.string, | ||
vol.Required(CONF_USERNAME): cv.string, | ||
}) | ||
|
||
SUPPORTED_FEATURES = (SUPPORT_OPEN | SUPPORT_CLOSE) | ||
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Set up the Ryobi covers.""" | ||
from py_ryobi_gdo import RyobiGDO as ryobi_door | ||
covers = [] | ||
|
||
username = config.get(CONF_USERNAME) | ||
password = config.get(CONF_PASSWORD) | ||
devices = config.get(CONF_DEVICE_ID) | ||
|
||
for device_id in devices: | ||
my_door = ryobi_door(username, password, device_id) | ||
_LOGGER.debug("Getting the API key") | ||
if my_door.get_api_key() is False: | ||
_LOGGER.error("Wrong credentials, no API key retrieved") | ||
return | ||
_LOGGER.debug("Checking if the device ID is present") | ||
if my_door.check_device_id() is False: | ||
_LOGGER.error("%s not in your device list", device_id) | ||
return | ||
_LOGGER.debug("Adding device %s to covers", device_id) | ||
covers.append(RyobiCover(hass, my_door)) | ||
if covers: | ||
_LOGGER.debug("Adding covers") | ||
add_devices(covers, True) | ||
|
||
|
||
class RyobiCover(CoverDevice): | ||
"""Representation of a ryobi cover.""" | ||
|
||
def __init__(self, hass, ryobi_door): | ||
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.
|
||
"""Initialize the cover.""" | ||
self.ryobi_door = ryobi_door | ||
self._name = 'ryobi_gdo_{}'.format(ryobi_door.get_device_id()) | ||
self._door_state = None | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of the cover.""" | ||
return self._name | ||
|
||
@property | ||
def is_closed(self): | ||
"""Return if the cover is closed.""" | ||
if self._door_state == STATE_UNKNOWN: | ||
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. It's not adding anything and unknown state is handled by the base entity class. |
||
return False | ||
return self._door_state == STATE_CLOSED | ||
|
||
@property | ||
def device_class(self): | ||
"""Return the class of this device, from component DEVICE_CLASSES.""" | ||
return 'garage' | ||
|
||
@property | ||
def supported_features(self): | ||
"""Flag supported features.""" | ||
return SUPPORTED_FEATURES | ||
|
||
def close_cover(self, **kwargs): | ||
"""Close the cover.""" | ||
_LOGGER.debug("Closing garage door") | ||
self.ryobi_door.close_device() | ||
|
||
def open_cover(self, **kwargs): | ||
"""Open the cover.""" | ||
_LOGGER.debug("Opening garage door") | ||
self.ryobi_door.open_device() | ||
|
||
def update(self): | ||
"""Update status from the door.""" | ||
_LOGGER.debug("Updating RyobiGDO status") | ||
self.ryobi_door.update() | ||
self._door_state = self.ryobi_door.get_door_status() |
This file contains 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.
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.
There's too much of debug logging in the module, without giving any specific info in the log messages. I'd remove everything but the one about adding devices.