Implement Datetime date component (#824)
Co-authored-by: J. Nick Koston <nick@koston.org> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
de7301b3ca
commit
f8ee918cdd
|
@ -45,6 +45,7 @@ service APIConnection {
|
|||
rpc button_command (ButtonCommandRequest) returns (void) {}
|
||||
rpc lock_command (LockCommandRequest) returns (void) {}
|
||||
rpc media_player_command (MediaPlayerCommandRequest) returns (void) {}
|
||||
rpc date_command (DateCommandRequest) returns (void) {}
|
||||
|
||||
rpc subscribe_bluetooth_le_advertisements (SubscribeBluetoothLEAdvertisementsRequest) returns (void) {}
|
||||
rpc bluetooth_device_request(BluetoothDeviceRequest) returns (void) {}
|
||||
|
@ -1617,3 +1618,45 @@ message TextCommandRequest {
|
|||
fixed32 key = 1;
|
||||
string state = 2;
|
||||
}
|
||||
|
||||
|
||||
// ==================== DATETIME DATE ====================
|
||||
message ListEntitiesDateResponse {
|
||||
option (id) = 100;
|
||||
option (source) = SOURCE_SERVER;
|
||||
option (ifdef) = "USE_DATETIME_DATE";
|
||||
|
||||
string object_id = 1;
|
||||
fixed32 key = 2;
|
||||
string name = 3;
|
||||
string unique_id = 4;
|
||||
|
||||
string icon = 5;
|
||||
bool disabled_by_default = 6;
|
||||
EntityCategory entity_category = 7;
|
||||
}
|
||||
message DateStateResponse {
|
||||
option (id) = 101;
|
||||
option (source) = SOURCE_SERVER;
|
||||
option (ifdef) = "USE_DATETIME_DATE";
|
||||
option (no_delay) = true;
|
||||
|
||||
fixed32 key = 1;
|
||||
// If the date does not have a valid state yet.
|
||||
// Equivalent to `!obj->has_state()` - inverse logic to make state packets smaller
|
||||
bool missing_state = 2;
|
||||
uint32 year = 3;
|
||||
uint32 month = 4;
|
||||
uint32 day = 5;
|
||||
}
|
||||
message DateCommandRequest {
|
||||
option (id) = 102;
|
||||
option (source) = SOURCE_CLIENT;
|
||||
option (ifdef) = "USE_DATETIME_DATE";
|
||||
option (no_delay) = true;
|
||||
|
||||
fixed32 key = 1;
|
||||
uint32 year = 2;
|
||||
uint32 month = 3;
|
||||
uint32 day = 4;
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -37,6 +37,7 @@ from .api_pb2 import ( # type: ignore
|
|||
CameraImageResponse,
|
||||
ClimateCommandRequest,
|
||||
CoverCommandRequest,
|
||||
DateCommandRequest,
|
||||
DeviceInfoRequest,
|
||||
DeviceInfoResponse,
|
||||
ExecuteServiceArgument,
|
||||
|
@ -1100,6 +1101,11 @@ class APIClient:
|
|||
def number_command(self, key: int, state: float) -> None:
|
||||
self._get_connection().send_message(NumberCommandRequest(key=key, state=state))
|
||||
|
||||
def date_command(self, key: int, year: int, month: int, day: int) -> None:
|
||||
self._get_connection().send_message(
|
||||
DateCommandRequest(key=key, year=year, month=month, day=day)
|
||||
)
|
||||
|
||||
def select_command(self, key: int, state: str) -> None:
|
||||
self._get_connection().send_message(SelectCommandRequest(key=key, state=state))
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ from .api_pb2 import ( # type: ignore
|
|||
ConnectResponse,
|
||||
CoverCommandRequest,
|
||||
CoverStateResponse,
|
||||
DateCommandRequest,
|
||||
DateStateResponse,
|
||||
DeviceInfoRequest,
|
||||
DeviceInfoResponse,
|
||||
DisconnectRequest,
|
||||
|
@ -59,6 +61,7 @@ from .api_pb2 import ( # type: ignore
|
|||
ListEntitiesCameraResponse,
|
||||
ListEntitiesClimateResponse,
|
||||
ListEntitiesCoverResponse,
|
||||
ListEntitiesDateResponse,
|
||||
ListEntitiesDoneResponse,
|
||||
ListEntitiesFanResponse,
|
||||
ListEntitiesLightResponse,
|
||||
|
@ -354,4 +357,7 @@ MESSAGE_TYPE_TO_PROTO = {
|
|||
97: ListEntitiesTextResponse,
|
||||
98: TextStateResponse,
|
||||
99: TextCommandRequest,
|
||||
100: ListEntitiesDateResponse,
|
||||
101: DateStateResponse,
|
||||
102: DateCommandRequest,
|
||||
}
|
||||
|
|
|
@ -637,6 +637,22 @@ class NumberState(EntityState):
|
|||
missing_state: bool = False
|
||||
|
||||
|
||||
# ==================== DATETIME DATE ====================
|
||||
|
||||
|
||||
@_frozen_dataclass_decorator
|
||||
class DateInfo(EntityInfo):
|
||||
pass
|
||||
|
||||
|
||||
@_frozen_dataclass_decorator
|
||||
class DateState(EntityState):
|
||||
missing_state: bool = False
|
||||
year: int = 0
|
||||
month: int = 0
|
||||
day: int = 0
|
||||
|
||||
|
||||
# ==================== SELECT ====================
|
||||
@_frozen_dataclass_decorator
|
||||
class SelectInfo(EntityInfo):
|
||||
|
@ -806,6 +822,7 @@ COMPONENT_TYPE_TO_INFO: dict[str, type[EntityInfo]] = {
|
|||
"camera": CameraInfo,
|
||||
"climate": ClimateInfo,
|
||||
"number": NumberInfo,
|
||||
"date": DateInfo,
|
||||
"select": SelectInfo,
|
||||
"siren": SirenInfo,
|
||||
"button": ButtonInfo,
|
||||
|
@ -1154,6 +1171,7 @@ _TYPE_TO_NAME = {
|
|||
FanInfo: "fan",
|
||||
LightInfo: "light",
|
||||
NumberInfo: "number",
|
||||
DateInfo: "date",
|
||||
SelectInfo: "select",
|
||||
SensorInfo: "sensor",
|
||||
SirenInfo: "siren",
|
||||
|
|
|
@ -7,6 +7,7 @@ from .api_pb2 import ( # type: ignore
|
|||
BinarySensorStateResponse,
|
||||
ClimateStateResponse,
|
||||
CoverStateResponse,
|
||||
DateStateResponse,
|
||||
FanStateResponse,
|
||||
LightStateResponse,
|
||||
ListEntitiesAlarmControlPanelResponse,
|
||||
|
@ -15,6 +16,7 @@ from .api_pb2 import ( # type: ignore
|
|||
ListEntitiesCameraResponse,
|
||||
ListEntitiesClimateResponse,
|
||||
ListEntitiesCoverResponse,
|
||||
ListEntitiesDateResponse,
|
||||
ListEntitiesFanResponse,
|
||||
ListEntitiesLightResponse,
|
||||
ListEntitiesLockResponse,
|
||||
|
@ -48,6 +50,8 @@ from .model import (
|
|||
ClimateState,
|
||||
CoverInfo,
|
||||
CoverState,
|
||||
DateInfo,
|
||||
DateState,
|
||||
EntityInfo,
|
||||
EntityState,
|
||||
FanInfo,
|
||||
|
@ -80,6 +84,7 @@ SUBSCRIBE_STATES_RESPONSE_TYPES: dict[Any, type[EntityState]] = {
|
|||
FanStateResponse: FanState,
|
||||
LightStateResponse: LightState,
|
||||
NumberStateResponse: NumberState,
|
||||
DateStateResponse: DateState,
|
||||
SelectStateResponse: SelectState,
|
||||
SensorStateResponse: SensorState,
|
||||
SirenStateResponse: SirenState,
|
||||
|
@ -99,6 +104,7 @@ LIST_ENTITIES_SERVICES_RESPONSE_TYPES: dict[Any, type[EntityInfo] | None] = {
|
|||
ListEntitiesFanResponse: FanInfo,
|
||||
ListEntitiesLightResponse: LightInfo,
|
||||
ListEntitiesNumberResponse: NumberInfo,
|
||||
ListEntitiesDateResponse: DateInfo,
|
||||
ListEntitiesSelectResponse: SelectInfo,
|
||||
ListEntitiesSensorResponse: SensorInfo,
|
||||
ListEntitiesSirenResponse: SirenInfo,
|
||||
|
|
|
@ -41,6 +41,7 @@ from aioesphomeapi.api_pb2 import (
|
|||
CameraImageResponse,
|
||||
ClimateCommandRequest,
|
||||
CoverCommandRequest,
|
||||
DateCommandRequest,
|
||||
DeviceInfoResponse,
|
||||
DisconnectResponse,
|
||||
ExecuteServiceArgument,
|
||||
|
@ -617,6 +618,29 @@ async def test_number_command(
|
|||
send.assert_called_once_with(NumberCommandRequest(**req))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"cmd, req",
|
||||
[
|
||||
(
|
||||
dict(key=1, year=2024, month=2, day=29),
|
||||
dict(key=1, year=2024, month=2, day=29),
|
||||
),
|
||||
(
|
||||
dict(key=1, year=2000, month=6, day=10),
|
||||
dict(key=1, year=2000, month=6, day=10),
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_date_command(
|
||||
auth_client: APIClient, cmd: dict[str, Any], req: dict[str, Any]
|
||||
) -> None:
|
||||
send = patch_send(auth_client)
|
||||
|
||||
auth_client.date_command(**cmd)
|
||||
send.assert_called_once_with(DateCommandRequest(**req))
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"cmd, req",
|
||||
|
|
|
@ -13,6 +13,7 @@ from aioesphomeapi.api_pb2 import (
|
|||
BluetoothGATTGetServicesResponse,
|
||||
ClimateStateResponse,
|
||||
CoverStateResponse,
|
||||
DateStateResponse,
|
||||
DeviceInfoResponse,
|
||||
FanStateResponse,
|
||||
HomeassistantServiceMap,
|
||||
|
@ -23,6 +24,7 @@ from aioesphomeapi.api_pb2 import (
|
|||
ListEntitiesButtonResponse,
|
||||
ListEntitiesClimateResponse,
|
||||
ListEntitiesCoverResponse,
|
||||
ListEntitiesDateResponse,
|
||||
ListEntitiesFanResponse,
|
||||
ListEntitiesLightResponse,
|
||||
ListEntitiesLockResponse,
|
||||
|
@ -69,6 +71,8 @@ from aioesphomeapi.model import (
|
|||
ClimateState,
|
||||
CoverInfo,
|
||||
CoverState,
|
||||
DateInfo,
|
||||
DateState,
|
||||
DeviceInfo,
|
||||
FanInfo,
|
||||
FanState,
|
||||
|
@ -242,6 +246,8 @@ def test_api_version_ord():
|
|||
(ClimateState, ClimateStateResponse),
|
||||
(NumberInfo, ListEntitiesNumberResponse),
|
||||
(NumberState, NumberStateResponse),
|
||||
(DateInfo, ListEntitiesDateResponse),
|
||||
(DateState, DateStateResponse),
|
||||
(SelectInfo, ListEntitiesSelectResponse),
|
||||
(SelectState, SelectStateResponse),
|
||||
(HomeassistantServiceCall, HomeassistantServiceResponse),
|
||||
|
@ -358,6 +364,7 @@ def test_user_service_conversion():
|
|||
FanInfo,
|
||||
LightInfo,
|
||||
NumberInfo,
|
||||
DateInfo,
|
||||
SelectInfo,
|
||||
SensorInfo,
|
||||
SirenInfo,
|
||||
|
|
Loading…
Reference in New Issue