-
-
Notifications
You must be signed in to change notification settings - Fork 31
Add support for the new ComfoConnect Pro #74
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
Open
jvanhees
wants to merge
2
commits into
michaelarnauts:master
Choose a base branch
from
jvanhees:comfoconnect-pro-connection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ | |
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| TIMEOUT = 5 | ||
| GATEWAY_TYPE_PRO = 2 | ||
|
|
||
|
|
||
| class SelfDeregistrationError(Exception): | ||
|
|
@@ -76,13 +77,20 @@ def fail_all(self, exc: Exception): | |
|
|
||
|
|
||
| class Bridge: | ||
| """ComfoConnect LAN C API.""" | ||
| """ComfoConnect LAN C / PRO API.""" | ||
|
|
||
| PORT = 56747 | ||
|
|
||
| def __init__(self, host: str, uuid: str, loop: Optional[asyncio.AbstractEventLoop] = None): | ||
| def __init__( | ||
| self, | ||
| host: str, | ||
| uuid: str, | ||
| loop: Optional[asyncio.AbstractEventLoop] = None, | ||
| bridge_type: int = 0, | ||
| ): | ||
| self.host: str = host | ||
| self.uuid: str = uuid | ||
| self.bridge_type: int = bridge_type | ||
| self._local_uuid: Optional[str] = None | ||
|
|
||
| self._reader: Optional[StreamReader] = None | ||
|
|
@@ -110,6 +118,32 @@ def set_alarm_callback(self, callback: Optional[Callable[[int, ProtobufMessage], | |
|
|
||
| async def connect(self, uuid: str): | ||
| """Connect to the bridge and start reading messages.""" | ||
| await self._open_connection(uuid) | ||
|
|
||
| async def register(self, uuid: str, name: str, pin: int) -> bool: | ||
| """Register this app on the bridge and start a session. | ||
|
|
||
| For LAN C bridges, attempts to start a session first; if the session | ||
| succeeds the app is already registered and no re-registration occurs. | ||
| For Pro bridges, registers directly to avoid a connection timeout that | ||
| the Pro issues when the app is not yet registered. | ||
|
|
||
| Returns True if the app was newly registered, False if it was already registered. | ||
| """ | ||
| await self._open_connection(uuid) | ||
| if self.bridge_type != GATEWAY_TYPE_PRO: | ||
| # LAN C: check whether we are already registered by starting a session. | ||
| try: | ||
| await self.cmd_start_session(True) | ||
| return False # Already registered; session is now active. | ||
| except ComfoConnectNotAllowed: | ||
| pass # Not registered yet; fall through to register below. | ||
|
Comment on lines
+134
to
+140
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. If we are ok with changing the actual behaviour, we could get rid of this part. I'm not really sure how that would work on the LAN C tho. |
||
| await self.cmd_register_app(uuid, name, pin) | ||
| await self.cmd_start_session(True) | ||
| return True | ||
|
|
||
| async def _open_connection(self, uuid: str): | ||
| """Open TCP connection to the bridge and start reading messages.""" | ||
| if self.is_connected(): | ||
| _LOGGER.warning("Already connected to bridge %s", self.host) | ||
| return | ||
|
|
||
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Oops, something went wrong.
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.
Might want to get this from the protobuf file.