Skip to content

Commit

Permalink
Add support of Homematic Control Unit (HCU)
Browse files Browse the repository at this point in the history
Requires the accesspoint id to be passed in the header and data
  • Loading branch information
dietzm committed Dec 6, 2024
1 parent 6a3c11a commit 519d8ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/homematicip/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ def __init__(self, home: Home):
"accept": "application/json",
"VERSION": "12",
"CLIENTAUTH": home._connection.clientauth_token,
"ACCESSPOINT-ID": home._connection.accesspoint_id,
}
self.url_rest = home._connection.urlREST
self.accesspoint_id = home._connection.accesspoint_id
self.pin = None

def connectionRequest(
Expand All @@ -35,7 +37,7 @@ def connectionRequest(
return response

def isRequestAcknowledged(self):
data = {"deviceId": self.uuid}
data = {"deviceId": self.uuid,"accessPointId":self.accesspoint_id}
response = requests.post(
"{}/hmip/auth/isRequestAcknowledged".format(self.url_rest),
json=data,
Expand Down
6 changes: 3 additions & 3 deletions src/homematicip/base/base_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ def clientauth_token(self):
return self._clientauth_token

def set_token_and_characteristics(self, accesspoint_id):
accesspoint_id = re.sub(r"[^a-fA-F0-9 ]", "", accesspoint_id).upper()
self._clientCharacteristics["id"] = accesspoint_id
self.accesspoint_id = re.sub(r"[^a-fA-F0-9 ]", "", accesspoint_id).upper()
self._clientCharacteristics["id"] = self.accesspoint_id
self._clientauth_token = (
hashlib.sha512(str(accesspoint_id + "jiLpVitHvWnIGD1yo7MA").encode("utf-8"))
hashlib.sha512(str(self.accesspoint_id + "jiLpVitHvWnIGD1yo7MA").encode("utf-8"))
.hexdigest()
.upper()
)
Expand Down
10 changes: 10 additions & 0 deletions src/homematicip/cli/hmip_generate_auth_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import time
from builtins import input

from pathlib import Path
import sys
path_root = Path(__file__).parents[2]
sys.path.append(str(path_root))
print(sys.path)

import homematicip
import homematicip.auth
from homematicip.home import Home
Expand Down Expand Up @@ -44,10 +50,14 @@ def main():
errorCode = json.loads(response.text)["errorCode"]
if errorCode == "INVALID_PIN":
print("PIN IS INVALID!")
elif errorCode == "ASSIGNMENT_LOCKED":
print("LOCKED ! Press button on HCU to unlock.")
time.sleep(5)
else:
print("Error: {}\nExiting".format(errorCode))
return

print("Connection Request successful!")
print("Please press the blue button on the access point")
while not auth.isRequestAcknowledged():
print("Please press the blue button on the access point")
Expand Down

0 comments on commit 519d8ad

Please sign in to comment.