-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* shbert-messages: Reworked SHC Light model. Added CommunicationQualityService. Added type messageCode fixed minor issues Corrected parameter count for register Introduced type SHCMessage
- Loading branch information
Showing
6 changed files
with
136 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import typing | ||
import logging | ||
|
||
logger = logging.getLogger("boschshcpy") | ||
|
||
class SHCMessage: | ||
def __init__(self, api, raw_message): | ||
self.api = api | ||
self._raw_message = raw_message | ||
|
||
class MessageCode: | ||
def __init__(self, message_code): | ||
self._message_code = message_code | ||
|
||
@property | ||
def name(self): | ||
return self._message_code["name"] | ||
|
||
@property | ||
def category(self): | ||
return self._message_code["category"] | ||
|
||
@property | ||
def id(self): | ||
return self._raw_message["id"] | ||
|
||
@property | ||
def message_code(self) -> MessageCode: | ||
return self._raw_message["messageCode"] | ||
|
||
@property | ||
def source_type(self): | ||
return self._raw_message["sourceType"] | ||
|
||
@property | ||
def timestamp(self): | ||
return self._raw_message["timestamp"] | ||
|
||
@property | ||
def flags(self): | ||
return self._raw_message["flags"] | ||
|
||
@property | ||
def arguments(self): | ||
return self._raw_message["arguments"] | ||
|
||
def summary(self): | ||
print(f"Message : {self.id}") | ||
print(f" Source : {self.source_type}") | ||
print(f" Timestamp : {self.timestamp}") | ||
print(f" MessageCode: {self.message_code}") | ||
_flags_string = "; ".join(self.flags) | ||
print(f" Flags : {_flags_string}") | ||
#_arguments_string = "; ".join(self.arguments) | ||
#print(f" Arguments : {_arguments_string}") | ||
print(f" Arguments : {self.arguments}") | ||
|
||
def process_long_polling_result(self, raw_result): | ||
assert raw_result["@type"] == "message" | ||
message_id = raw_result["id"] | ||
logger.debug( | ||
f"Got long polling result, not yet supported {message_id}" | ||
) | ||
|
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,45 @@ | ||
#!/usr/bin/env python | ||
|
||
# Use this script to see messages from api | ||
|
||
import os, sys | ||
import time | ||
import logging | ||
from datetime import datetime | ||
|
||
sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | ||
|
||
import boschshcpy | ||
|
||
logger = logging.getLogger("boschshcpy") | ||
|
||
def api_test(): | ||
session = boschshcpy.SHCSession(args.ip_address, args.access_cert, args.access_key, False) | ||
#session.information.summary() | ||
logger.debug("getting messages") | ||
for _message in session.messages: | ||
print(f"Timestamp of message: {datetime.fromtimestamp(_message.timestamp/1000.0)}") | ||
_message.summary() | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse, sys | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-ac", "--access_cert", | ||
help="Path to access certificate.", | ||
default="keystore/boschshc-cert.pem") | ||
parser.add_argument("-ak", "--access_key", | ||
help="Path to access key.", | ||
default="keystore/boschshc-key.pem") | ||
parser.add_argument("-ip", "--ip_address", | ||
help="IP of the smart home controller.") | ||
args = parser.parse_args() | ||
|
||
if len(sys.argv) == 1: | ||
parser.print_help() | ||
sys.exit() | ||
|
||
api_test() |
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