This commit is contained in:
Otto Winter 2019-01-19 15:10:00 +01:00
parent 9e7c0b9101
commit d4c04f46e9
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
3 changed files with 219 additions and 59 deletions

View File

@ -172,6 +172,12 @@ message ListEntitiesTextSensorResponse {
string icon = 5;
}
message ListEntitiesCameraResponse {
string object_id = 1;
fixed32 key = 2;
string name = 3;
string unique_id = 4;
}
message ListEntitiesDoneResponse {
// Empty
}
@ -225,6 +231,11 @@ message TextSensorStateResponse {
fixed32 key = 1;
string state = 2;
}
message CameraImageResponse {
fixed32 key = 1;
bytes data = 2;
bool done = 3;
}
message CoverCommandRequest {
fixed32 key = 1;
@ -290,6 +301,7 @@ message SubscribeLogsResponse {
LogLevel level = 1;
string tag = 2;
string message = 3;
bool send_failed = 4;
}
message SubscribeServiceCallsRequest {

File diff suppressed because one or more lines are too long

View File

@ -57,6 +57,8 @@ MESSAGE_TYPE_TO_PROTO = {
38: pb.SubscribeHomeAssistantStatesRequest,
39: pb.SubscribeHomeAssistantStateResponse,
40: pb.HomeAssistantStateResponse,
41: pb.ListEntitiesCameraResponse,
42: pb.CameraImageResponse,
}
@ -236,6 +238,16 @@ class TextSensorState(EntityState):
state = attr.ib(type=str)
@attr.s
class CameraInfo(EntityInfo):
pass
@attr.s
class CameraState(EntityState):
image = attr.ib(type=bytes)
COMPONENT_TYPE_TO_INFO = {
'binary_sensor': BinarySensorInfo,
'cover': CoverInfo,
@ -244,6 +256,7 @@ COMPONENT_TYPE_TO_INFO = {
'sensor': SensorInfo,
'switch': SwitchInfo,
'text_sensor': TextSensorInfo,
'camera': CameraInfo,
}
@ -655,6 +668,7 @@ class APIClient:
pb.ListEntitiesSensorResponse: SensorInfo,
pb.ListEntitiesSwitchResponse: SwitchInfo,
pb.ListEntitiesTextSensorResponse: TextSensorInfo,
pb.ListEntitiesCameraResponse: CameraInfo,
}
def do_append(msg):
@ -690,7 +704,21 @@ class APIClient:
pb.TextSensorStateResponse: TextSensorState,
}
image_stream = {}
def on_msg(msg):
if isinstance(msg, pb.CameraImageResponse):
data = image_stream.pop(msg.key, bytes()) + msg.data
if msg.done:
on_state(CameraState(key=msg.key, image=data))
hash_ = 0
for x in data:
hash_ ^= x
_LOGGER.warning("Got image hash=%s len=%s", hex(hash_), len(data))
else:
image_stream[msg.key] = data
return
for resp_type, cls in response_types.items():
if isinstance(msg, resp_type):
break