This repository was archived by the owner on Nov 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbe0c4d
commit de2fde1
Showing
7 changed files
with
800 additions
and
596 deletions.
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
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 |
---|---|---|
@@ -1,93 +1,13 @@ | ||
""" | ||
PyComfoConnect: Manage your Zehnder ComfoConnect Q350/Q450/Q650 ventilation unit | ||
""" | ||
from __future__ import print_function | ||
|
||
from .bridge import * | ||
from .const import * | ||
from .error import * | ||
from .message import * | ||
from .zehnder_pb2 import * | ||
|
||
|
||
class ComfoConnect(object): | ||
def __init__(self, bridge: Bridge, callback=None, debug=False): | ||
self._bridge = bridge | ||
self._callback = callback | ||
self.requests = [] | ||
|
||
# Set debug mode | ||
self._bridge.debug = debug | ||
|
||
def connect(self, local_uuid, local_name, pin): | ||
"""Connect to the bridge and login.""" | ||
|
||
try: | ||
# Open connection | ||
self._bridge.connect(local_uuid, self._callback_method) | ||
|
||
# Login | ||
self._bridge.StartSession(False) | ||
|
||
except PyComfoConnectNotAllowed: | ||
# Register with the bridge | ||
self._bridge.RegisterApp(local_name, pin) | ||
|
||
# Login | ||
self._bridge.StartSession(False) | ||
|
||
# Request version info | ||
version_info = self._bridge.VersionRequest() | ||
return version_info | ||
|
||
def disconnect(self): | ||
"""Logout and disconnect from the bridge.""" | ||
DEFAULT_UUID = '00000000000000000000000000000001' | ||
DEFAULT_NAME = 'pycomfoconnect' | ||
DEFAULT_PIN = 0 | ||
|
||
# Logout | ||
self._bridge.CloseSession() | ||
__author__ = 'Michaël Arnauts <[email protected]>' | ||
|
||
# Close socket connection | ||
self._bridge.disconnect() | ||
|
||
def is_connected(self): | ||
"""Check if we are still connected to the bridge.""" | ||
return self._bridge.is_connected() | ||
|
||
def _callback_method(self, msg: Message): | ||
if self._callback is None: | ||
return False | ||
|
||
if msg.cmd.type != zehnder_pb2.GatewayOperation.CnRpdoNotificationType: | ||
return False | ||
|
||
data = msg.msg.data.hex() | ||
if len(data) == 2: | ||
val = struct.unpack('b', msg.msg.data)[0] | ||
elif len(data) == 4: | ||
val = struct.unpack('h', msg.msg.data)[0] | ||
elif len(data) == 8: | ||
val = data | ||
else: | ||
val = data | ||
|
||
self._callback(msg.msg.pdid, val) | ||
|
||
def set_fan_mode(self, mode: int, node: int = 1): | ||
if mode == FAN_MODE_AWAY: | ||
cmd = CMD_FAN_MODE_AWAY | ||
elif mode == FAN_MODE_LOW: | ||
cmd = CMD_FAN_MODE_LOW | ||
elif mode == FAN_MODE_MEDIUM: | ||
cmd = CMD_FAN_MODE_MEDIUM | ||
elif mode == FAN_MODE_HIGH: | ||
cmd = CMD_FAN_MODE_HIGH | ||
else: | ||
raise Exception('Unknown fan mode.') | ||
|
||
self._bridge.CnRmiRequest(node, cmd) | ||
|
||
def request(self, parameter, node=1): | ||
if not parameter in SIZE_MAP: | ||
raise Exception('Unknown parameter.') | ||
|
||
self._bridge.CnRpdoRequest(parameter, node, SIZE_MAP.get(parameter)) | ||
from .comfoconnect import * | ||
from .error import * | ||
from .const import * |
Oops, something went wrong.