-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Support for new velux api, added cover.velux #18738
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
17 commits
Select commit
Hold shift + click to select a range
6f94e13
Support for new velux api, added cover.velux
Julius2342 e21d6fb
Merge remote-tracking branch 'upstream/dev' into new-velux-api
Julius2342 f88766c
More steps on new velux covers.
Julius2342 6a9e13d
Merge branch 'dev' into new-velux-api
Julius2342 6a7aaab
correct position handling of velux windows
Julius2342 5af2b09
Merge remote-tracking branch 'upstream/dev' into new-velux-api
Julius2342 3968a5f
Following suggestion from hound.
Julius2342 abfd9e0
Merge remote-tracking branch 'upstream/dev' into new-velux-api
Julius2342 7b706f7
bumped version
Julius2342 24df5d5
added cover stop
Julius2342 cabb155
bumped version of pyvlx
Julius2342 d40f008
Merge remote-tracking branch 'upstream/dev' into new-velux-api
Julius2342 a485798
Merge remote-tracking branch 'upstream/dev' into new-velux-api
Julius2342 f3c934c
Merge remote-tracking branch 'upstream/dev' into new-velux-api
Julius2342 15d1de8
Merge remote-tracking branch 'upstream/dev' into new-velux-api
Julius2342 13822bb
Bumped version to 0.2.8
Julius2342 4828212
removed log_frames parameter
Julius2342 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| """ | ||
| Support for Velux covers. | ||
|
|
||
| For more details about this platform, please refer to the documentation at | ||
| https://home-assistant.io/components/cover.velux/ | ||
| """ | ||
|
|
||
| from homeassistant.components.cover import ( | ||
| ATTR_POSITION, SUPPORT_CLOSE, SUPPORT_OPEN, SUPPORT_SET_POSITION, | ||
| SUPPORT_STOP, CoverDevice) | ||
| from homeassistant.components.velux import DATA_VELUX | ||
| from homeassistant.core import callback | ||
|
|
||
| DEPENDENCIES = ['velux'] | ||
|
|
||
|
|
||
| async def async_setup_platform(hass, config, async_add_entities, | ||
| discovery_info=None): | ||
| """Set up cover(s) for Velux platform.""" | ||
| entities = [] | ||
| for node in hass.data[DATA_VELUX].pyvlx.nodes: | ||
| from pyvlx import OpeningDevice | ||
| if isinstance(node, OpeningDevice): | ||
| entities.append(VeluxCover(node)) | ||
| async_add_entities(entities) | ||
|
|
||
|
|
||
| class VeluxCover(CoverDevice): | ||
| """Representation of a Velux cover.""" | ||
|
|
||
| def __init__(self, node): | ||
| """Initialize the cover.""" | ||
| self.node = node | ||
|
|
||
| @callback | ||
| def async_register_callbacks(self): | ||
| """Register callbacks to update hass after device was changed.""" | ||
| async def after_update_callback(device): | ||
| """Call after device was updated.""" | ||
| await self.async_update_ha_state() | ||
| self.node.register_device_updated_cb(after_update_callback) | ||
|
|
||
| async def async_added_to_hass(self): | ||
| """Store register state change callback.""" | ||
| self.async_register_callbacks() | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the Velux device.""" | ||
| return self.node.name | ||
|
|
||
| @property | ||
| def should_poll(self): | ||
| """No polling needed within Velux.""" | ||
| return False | ||
|
|
||
| @property | ||
| def supported_features(self): | ||
| """Flag supported features.""" | ||
| return SUPPORT_OPEN | SUPPORT_CLOSE | \ | ||
| SUPPORT_SET_POSITION | SUPPORT_STOP | ||
|
|
||
| @property | ||
| def current_cover_position(self): | ||
| """Return the current position of the cover.""" | ||
| return 100 - self.node.position.position_percent | ||
|
|
||
| @property | ||
| def device_class(self): | ||
| """Define this cover as a window.""" | ||
| return 'window' | ||
|
|
||
| @property | ||
| def is_closed(self): | ||
| """Return if the cover is closed.""" | ||
| return self.node.position.closed | ||
|
|
||
| async def async_close_cover(self, **kwargs): | ||
| """Close the cover.""" | ||
| await self.node.close() | ||
|
|
||
| async def async_open_cover(self, **kwargs): | ||
| """Open the cover.""" | ||
| await self.node.open() | ||
|
|
||
| async def async_set_cover_position(self, **kwargs): | ||
| """Move the cover to a specific position.""" | ||
| if ATTR_POSITION in kwargs: | ||
|
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 already validated by the service schema. |
||
| position_percent = 100 - kwargs[ATTR_POSITION] | ||
| from pyvlx import Position | ||
| await self.node.set_position( | ||
| Position(position_percent=position_percent)) | ||
|
|
||
| async def async_stop_cover(self, **kwargs): | ||
| """Stop the cover.""" | ||
| await self.node.stop() | ||
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
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.
Question, should the
async defbe outside of thedef? I'm not 100% familiar with this yet.example: cover.template.pyL201
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.
I think that's okay, as it is just passed as a callback (which I assume gets awaited later on). The @callback marks this as something that does not do I/O (for optimization), see: https://developers.home-assistant.io/docs/en/asyncio_categorizing_functions.html#the-callback-function