mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2025-01-26 22:22:10 +01:00
Add number entities (#47)
This commit is contained in:
parent
4b751bed8b
commit
e0f09de715
@ -38,6 +38,7 @@ service APIConnection {
|
||||
rpc switch_command (SwitchCommandRequest) returns (void) {}
|
||||
rpc camera_image (CameraImageRequest) returns (void) {}
|
||||
rpc climate_command (ClimateCommandRequest) returns (void) {}
|
||||
rpc number_command (NumberCommandRequest) returns (void) {}
|
||||
}
|
||||
|
||||
|
||||
@ -791,3 +792,41 @@ message ClimateCommandRequest {
|
||||
bool has_custom_preset = 20;
|
||||
string custom_preset = 21;
|
||||
}
|
||||
|
||||
// ==================== NUMBER ====================
|
||||
message ListEntitiesNumberResponse {
|
||||
option (id) = 49;
|
||||
option (source) = SOURCE_SERVER;
|
||||
option (ifdef) = "USE_NUMBER";
|
||||
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
|
||||
string icon = 5;
|
||||
float min_value = 6;
|
||||
float max_value = 7;
|
||||
float step = 8;
|
||||
}
|
||||
message NumberStateResponse {
|
||||
option (id) = 50;
|
||||
option (source) = SOURCE_SERVER;
|
||||
option (ifdef) = "USE_NUMBER";
|
||||
option (no_delay) = true;
|
||||
|
||||
fixed32 key = 1;
|
||||
float state = 2;
|
||||
// If the number does not have a valid state yet.
|
||||
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
|
||||
bool missing_state = 3;
|
||||
}
|
||||
message NumberCommandRequest {
|
||||
option (id) = 51;
|
||||
option (source) = SOURCE_CLIENT;
|
||||
option (ifdef) = "USE_NUMBER";
|
||||
option (no_delay) = true;
|
||||
|
||||
fixed32 key = 1;
|
||||
float state = 2;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -42,11 +42,14 @@ from aioesphomeapi.api_pb2 import ( # type: ignore
|
||||
ListEntitiesDoneResponse,
|
||||
ListEntitiesFanResponse,
|
||||
ListEntitiesLightResponse,
|
||||
ListEntitiesNumberResponse,
|
||||
ListEntitiesRequest,
|
||||
ListEntitiesSensorResponse,
|
||||
ListEntitiesServicesResponse,
|
||||
ListEntitiesSwitchResponse,
|
||||
ListEntitiesTextSensorResponse,
|
||||
NumberCommandRequest,
|
||||
NumberStateResponse,
|
||||
SensorStateResponse,
|
||||
SubscribeHomeassistantServicesRequest,
|
||||
SubscribeHomeAssistantStateResponse,
|
||||
@ -84,6 +87,8 @@ from aioesphomeapi.model import (
|
||||
LegacyCoverCommand,
|
||||
LightInfo,
|
||||
LightState,
|
||||
NumberInfo,
|
||||
NumberState,
|
||||
SensorInfo,
|
||||
SensorState,
|
||||
SwitchInfo,
|
||||
@ -206,6 +211,7 @@ class APIClient:
|
||||
ListEntitiesCoverResponse: CoverInfo,
|
||||
ListEntitiesFanResponse: FanInfo,
|
||||
ListEntitiesLightResponse: LightInfo,
|
||||
ListEntitiesNumberResponse: NumberInfo,
|
||||
ListEntitiesSensorResponse: SensorInfo,
|
||||
ListEntitiesSwitchResponse: SwitchInfo,
|
||||
ListEntitiesTextSensorResponse: TextSensorInfo,
|
||||
@ -265,6 +271,7 @@ class APIClient:
|
||||
CoverStateResponse: CoverState,
|
||||
FanStateResponse: FanState,
|
||||
LightStateResponse: LightState,
|
||||
NumberStateResponse: NumberState,
|
||||
SensorStateResponse: SensorState,
|
||||
SwitchStateResponse: SwitchState,
|
||||
TextSensorStateResponse: TextSensorState,
|
||||
@ -530,6 +537,15 @@ class APIClient:
|
||||
assert self._connection is not None
|
||||
await self._connection.send_message(req)
|
||||
|
||||
async def number_command(self, key: int, state: float) -> None:
|
||||
self._check_authenticated()
|
||||
|
||||
req = NumberCommandRequest()
|
||||
req.key = key
|
||||
req.state = state
|
||||
assert self._connection is not None
|
||||
await self._connection.send_message(req)
|
||||
|
||||
async def execute_service(
|
||||
self, service: UserService, data: ExecuteServiceDataType
|
||||
) -> None:
|
||||
|
@ -30,11 +30,14 @@ from aioesphomeapi.api_pb2 import ( # type: ignore
|
||||
ListEntitiesDoneResponse,
|
||||
ListEntitiesFanResponse,
|
||||
ListEntitiesLightResponse,
|
||||
ListEntitiesNumberResponse,
|
||||
ListEntitiesRequest,
|
||||
ListEntitiesSensorResponse,
|
||||
ListEntitiesServicesResponse,
|
||||
ListEntitiesSwitchResponse,
|
||||
ListEntitiesTextSensorResponse,
|
||||
NumberCommandRequest,
|
||||
NumberStateResponse,
|
||||
PingRequest,
|
||||
PingResponse,
|
||||
SensorStateResponse,
|
||||
@ -103,4 +106,7 @@ MESSAGE_TYPE_TO_PROTO = {
|
||||
46: ListEntitiesClimateResponse,
|
||||
47: ClimateStateResponse,
|
||||
48: ClimateCommandRequest,
|
||||
49: ListEntitiesNumberResponse,
|
||||
50: NumberStateResponse,
|
||||
51: NumberCommandRequest,
|
||||
}
|
||||
|
@ -379,6 +379,21 @@ class ClimateState(EntityState):
|
||||
return self.preset
|
||||
|
||||
|
||||
# ==================== NUMBER ====================
|
||||
@attr.s
|
||||
class NumberInfo(EntityInfo):
|
||||
icon = attr.ib(type=str, default="")
|
||||
min_value = attr.ib(type=float, default=0.0)
|
||||
max_value = attr.ib(type=float, default=0.0)
|
||||
step = attr.ib(type=float, default=0.0)
|
||||
|
||||
|
||||
@attr.s
|
||||
class NumberState(EntityState):
|
||||
state = attr.ib(type=float, default=0.0)
|
||||
missing_state = attr.ib(type=bool, default=False)
|
||||
|
||||
|
||||
COMPONENT_TYPE_TO_INFO = {
|
||||
"binary_sensor": BinarySensorInfo,
|
||||
"cover": CoverInfo,
|
||||
@ -389,6 +404,7 @@ COMPONENT_TYPE_TO_INFO = {
|
||||
"text_sensor": TextSensorInfo,
|
||||
"camera": CameraInfo,
|
||||
"climate": ClimateInfo,
|
||||
"number": NumberInfo,
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user