Rename ServiceCall to HomeassistantServiceCall

This commit is contained in:
Otto Winter 2019-06-18 11:10:32 +02:00
parent 7ade99a614
commit 2b7a4b27b3
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
5 changed files with 131 additions and 118 deletions

View File

@ -4,31 +4,31 @@ import "api_options.proto";
service APIConnection {
rpc hello (HelloRequest) returns (HelloResponse) {
option (needs_setup_connection) = false;
option (needs_authentication) = false;
option (needs_setup_connection) = false;
option (needs_authentication) = false;
}
rpc connect (ConnectRequest) returns (ConnectResponse) {
option (needs_setup_connection) = false;
option (needs_authentication) = false;
option (needs_setup_connection) = false;
option (needs_authentication) = false;
}
rpc disconnect (DisconnectRequest) returns (DisconnectResponse) {
option (needs_setup_connection) = false;
option (needs_authentication) = false;
option (needs_setup_connection) = false;
option (needs_authentication) = false;
}
rpc ping (PingRequest) returns (PingResponse) {
option (needs_setup_connection) = false;
option (needs_authentication) = false;
option (needs_setup_connection) = false;
option (needs_authentication) = false;
}
rpc device_info (DeviceInfoRequest) returns (DeviceInfoResponse) {
option (needs_authentication) = false;
option (needs_authentication) = false;
}
rpc list_entities (ListEntitiesRequest) returns (void) {}
rpc subscribe_states (SubscribeStatesRequest) returns (void) {}
rpc subscribe_logs (SubscribeLogsRequest) returns (void) {}
rpc subscribe_service_calls (SubscribeServiceCallsRequest) returns (void) {}
rpc subscribe_homeassistant_services (SubscribeHomeassistantServicesRequest) returns (void) {}
rpc subscribe_home_assistant_states (SubscribeHomeAssistantStatesRequest) returns (void) {}
rpc get_time (GetTimeRequest) returns (GetTimeResponse) {
option (needs_authentication) = false;
option (needs_authentication) = false;
}
rpc execute_service (ExecuteServiceRequest) returns (void) {}
@ -502,25 +502,26 @@ message SubscribeLogsResponse {
}
// ==================== HOMEASSISTANT.SERVICE ====================
message SubscribeServiceCallsRequest {
message SubscribeHomeassistantServicesRequest {
option (id) = 34;
option (source) = SOURCE_CLIENT;
}
message ServiceCallMap {
message HomeassistantServiceMap {
string key = 1;
string value = 2;
}
message ServiceCallResponse {
message HomeassistantServiceResponse {
option (id) = 35;
option (source) = SOURCE_SERVER;
option (no_delay) = true;
string service = 1;
repeated ServiceCallMap data = 2;
repeated ServiceCallMap data_template = 3;
repeated ServiceCallMap variables = 4;
repeated HomeassistantServiceMap data = 2;
repeated HomeassistantServiceMap data_template = 3;
repeated HomeassistantServiceMap variables = 4;
bool is_event = 5;
}
// ==================== IMPORT HOME ASSISTANT STATES ====================

File diff suppressed because one or more lines are too long

View File

@ -184,17 +184,17 @@ class APIClient:
req.level = log_level
await self._connection.send_message_callback_response(req, on_msg)
async def subscribe_service_calls(self, on_service_call: Callable[[ServiceCall], None]) -> None:
async def subscribe_service_calls(self, on_service_call: Callable[[HomeassistantServiceCall], None]) -> None:
self._check_authenticated()
def on_msg(msg):
if isinstance(msg, pb.ServiceCallResponse):
if isinstance(msg, pb.HomeassistantServiceResponse):
kwargs = {}
for key, _ in attr.fields_dict(ServiceCall).items():
for key, _ in attr.fields_dict(HomeassistantServiceCall).items():
kwargs[key] = getattr(msg, key)
on_service_call(ServiceCall(**kwargs))
on_service_call(HomeassistantServiceCall(**kwargs))
await self._connection.send_message_callback_response(pb.SubscribeServiceCallsRequest(),
await self._connection.send_message_callback_response(pb.SubscribeHomeassistantServicesRequest(),
on_msg)
async def subscribe_home_assistant_states(self, on_state_sub: Callable[[str], None]) -> None:

View File

@ -39,8 +39,8 @@ MESSAGE_TYPE_TO_PROTO = {
31: pb.FanCommandRequest,
32: pb.LightCommandRequest,
33: pb.SwitchCommandRequest,
34: pb.SubscribeServiceCallsRequest,
35: pb.ServiceCallResponse,
34: pb.SubscribeHomeassistantServicesRequest,
35: pb.HomeassistantServiceResponse,
36: pb.GetTimeRequest,
37: pb.GetTimeResponse,
38: pb.SubscribeHomeAssistantStatesRequest,

View File

@ -223,12 +223,17 @@ COMPONENT_TYPE_TO_INFO = {
# ==================== USER-DEFINED SERVICES ====================
def _convert_homeassistant_service_map(value):
return {v.key: v.value for v in value}
@attr.s
class ServiceCall:
class HomeassistantServiceCall:
service = attr.ib(type=str)
data = attr.ib(type=Dict[str, str], converter=dict)
data_template = attr.ib(type=Dict[str, str], converter=dict)
variables = attr.ib(type=Dict[str, str], converter=dict)
is_event = attr.ib(type=bool)
data = attr.ib(type=Dict[str, str], converter=_convert_homeassistant_service_map)
data_template = attr.ib(type=Dict[str, str], converter=_convert_homeassistant_service_map)
variables = attr.ib(type=Dict[str, str], converter=_convert_homeassistant_service_map)
class UserServiceArgType(enum.IntEnum):