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 button_command (ButtonCommandRequest) returns (void) {}
|
||||||
rpc lock_command (LockCommandRequest) returns (void) {}
|
rpc lock_command (LockCommandRequest) returns (void) {}
|
||||||
rpc media_player_command (MediaPlayerCommandRequest) returns (void) {}
|
rpc media_player_command (MediaPlayerCommandRequest) returns (void) {}
|
||||||
|
rpc date_command (DateCommandRequest) returns (void) {}
|
||||||
|
|
||||||
rpc subscribe_bluetooth_le_advertisements (SubscribeBluetoothLEAdvertisementsRequest) returns (void) {}
|
rpc subscribe_bluetooth_le_advertisements (SubscribeBluetoothLEAdvertisementsRequest) returns (void) {}
|
||||||
rpc bluetooth_device_request(BluetoothDeviceRequest) returns (void) {}
|
rpc bluetooth_device_request(BluetoothDeviceRequest) returns (void) {}
|
||||||
|
@ -1617,3 +1618,45 @@ message TextCommandRequest {
|
||||||
fixed32 key = 1;
|
fixed32 key = 1;
|
||||||
string state = 2;
|
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,
|
CameraImageResponse,
|
||||||
ClimateCommandRequest,
|
ClimateCommandRequest,
|
||||||
CoverCommandRequest,
|
CoverCommandRequest,
|
||||||
|
DateCommandRequest,
|
||||||
DeviceInfoRequest,
|
DeviceInfoRequest,
|
||||||
DeviceInfoResponse,
|
DeviceInfoResponse,
|
||||||
ExecuteServiceArgument,
|
ExecuteServiceArgument,
|
||||||
|
@ -1100,6 +1101,11 @@ class APIClient:
|
||||||
def number_command(self, key: int, state: float) -> None:
|
def number_command(self, key: int, state: float) -> None:
|
||||||
self._get_connection().send_message(NumberCommandRequest(key=key, state=state))
|
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:
|
def select_command(self, key: int, state: str) -> None:
|
||||||
self._get_connection().send_message(SelectCommandRequest(key=key, state=state))
|
self._get_connection().send_message(SelectCommandRequest(key=key, state=state))
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ from .api_pb2 import ( # type: ignore
|
||||||
ConnectResponse,
|
ConnectResponse,
|
||||||
CoverCommandRequest,
|
CoverCommandRequest,
|
||||||
CoverStateResponse,
|
CoverStateResponse,
|
||||||
|
DateCommandRequest,
|
||||||
|
DateStateResponse,
|
||||||
DeviceInfoRequest,
|
DeviceInfoRequest,
|
||||||
DeviceInfoResponse,
|
DeviceInfoResponse,
|
||||||
DisconnectRequest,
|
DisconnectRequest,
|
||||||
|
@ -59,6 +61,7 @@ from .api_pb2 import ( # type: ignore
|
||||||
ListEntitiesCameraResponse,
|
ListEntitiesCameraResponse,
|
||||||
ListEntitiesClimateResponse,
|
ListEntitiesClimateResponse,
|
||||||
ListEntitiesCoverResponse,
|
ListEntitiesCoverResponse,
|
||||||
|
ListEntitiesDateResponse,
|
||||||
ListEntitiesDoneResponse,
|
ListEntitiesDoneResponse,
|
||||||
ListEntitiesFanResponse,
|
ListEntitiesFanResponse,
|
||||||
ListEntitiesLightResponse,
|
ListEntitiesLightResponse,
|
||||||
|
@ -354,4 +357,7 @@ MESSAGE_TYPE_TO_PROTO = {
|
||||||
97: ListEntitiesTextResponse,
|
97: ListEntitiesTextResponse,
|
||||||
98: TextStateResponse,
|
98: TextStateResponse,
|
||||||
99: TextCommandRequest,
|
99: TextCommandRequest,
|
||||||
|
100: ListEntitiesDateResponse,
|
||||||
|
101: DateStateResponse,
|
||||||
|
102: DateCommandRequest,
|
||||||
}
|
}
|
||||||
|
|
|
@ -637,6 +637,22 @@ class NumberState(EntityState):
|
||||||
missing_state: bool = False
|
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 ====================
|
# ==================== SELECT ====================
|
||||||
@_frozen_dataclass_decorator
|
@_frozen_dataclass_decorator
|
||||||
class SelectInfo(EntityInfo):
|
class SelectInfo(EntityInfo):
|
||||||
|
@ -806,6 +822,7 @@ COMPONENT_TYPE_TO_INFO: dict[str, type[EntityInfo]] = {
|
||||||
"camera": CameraInfo,
|
"camera": CameraInfo,
|
||||||
"climate": ClimateInfo,
|
"climate": ClimateInfo,
|
||||||
"number": NumberInfo,
|
"number": NumberInfo,
|
||||||
|
"date": DateInfo,
|
||||||
"select": SelectInfo,
|
"select": SelectInfo,
|
||||||
"siren": SirenInfo,
|
"siren": SirenInfo,
|
||||||
"button": ButtonInfo,
|
"button": ButtonInfo,
|
||||||
|
@ -1154,6 +1171,7 @@ _TYPE_TO_NAME = {
|
||||||
FanInfo: "fan",
|
FanInfo: "fan",
|
||||||
LightInfo: "light",
|
LightInfo: "light",
|
||||||
NumberInfo: "number",
|
NumberInfo: "number",
|
||||||
|
DateInfo: "date",
|
||||||
SelectInfo: "select",
|
SelectInfo: "select",
|
||||||
SensorInfo: "sensor",
|
SensorInfo: "sensor",
|
||||||
SirenInfo: "siren",
|
SirenInfo: "siren",
|
||||||
|
|
|
@ -7,6 +7,7 @@ from .api_pb2 import ( # type: ignore
|
||||||
BinarySensorStateResponse,
|
BinarySensorStateResponse,
|
||||||
ClimateStateResponse,
|
ClimateStateResponse,
|
||||||
CoverStateResponse,
|
CoverStateResponse,
|
||||||
|
DateStateResponse,
|
||||||
FanStateResponse,
|
FanStateResponse,
|
||||||
LightStateResponse,
|
LightStateResponse,
|
||||||
ListEntitiesAlarmControlPanelResponse,
|
ListEntitiesAlarmControlPanelResponse,
|
||||||
|
@ -15,6 +16,7 @@ from .api_pb2 import ( # type: ignore
|
||||||
ListEntitiesCameraResponse,
|
ListEntitiesCameraResponse,
|
||||||
ListEntitiesClimateResponse,
|
ListEntitiesClimateResponse,
|
||||||
ListEntitiesCoverResponse,
|
ListEntitiesCoverResponse,
|
||||||
|
ListEntitiesDateResponse,
|
||||||
ListEntitiesFanResponse,
|
ListEntitiesFanResponse,
|
||||||
ListEntitiesLightResponse,
|
ListEntitiesLightResponse,
|
||||||
ListEntitiesLockResponse,
|
ListEntitiesLockResponse,
|
||||||
|
@ -48,6 +50,8 @@ from .model import (
|
||||||
ClimateState,
|
ClimateState,
|
||||||
CoverInfo,
|
CoverInfo,
|
||||||
CoverState,
|
CoverState,
|
||||||
|
DateInfo,
|
||||||
|
DateState,
|
||||||
EntityInfo,
|
EntityInfo,
|
||||||
EntityState,
|
EntityState,
|
||||||
FanInfo,
|
FanInfo,
|
||||||
|
@ -80,6 +84,7 @@ SUBSCRIBE_STATES_RESPONSE_TYPES: dict[Any, type[EntityState]] = {
|
||||||
FanStateResponse: FanState,
|
FanStateResponse: FanState,
|
||||||
LightStateResponse: LightState,
|
LightStateResponse: LightState,
|
||||||
NumberStateResponse: NumberState,
|
NumberStateResponse: NumberState,
|
||||||
|
DateStateResponse: DateState,
|
||||||
SelectStateResponse: SelectState,
|
SelectStateResponse: SelectState,
|
||||||
SensorStateResponse: SensorState,
|
SensorStateResponse: SensorState,
|
||||||
SirenStateResponse: SirenState,
|
SirenStateResponse: SirenState,
|
||||||
|
@ -99,6 +104,7 @@ LIST_ENTITIES_SERVICES_RESPONSE_TYPES: dict[Any, type[EntityInfo] | None] = {
|
||||||
ListEntitiesFanResponse: FanInfo,
|
ListEntitiesFanResponse: FanInfo,
|
||||||
ListEntitiesLightResponse: LightInfo,
|
ListEntitiesLightResponse: LightInfo,
|
||||||
ListEntitiesNumberResponse: NumberInfo,
|
ListEntitiesNumberResponse: NumberInfo,
|
||||||
|
ListEntitiesDateResponse: DateInfo,
|
||||||
ListEntitiesSelectResponse: SelectInfo,
|
ListEntitiesSelectResponse: SelectInfo,
|
||||||
ListEntitiesSensorResponse: SensorInfo,
|
ListEntitiesSensorResponse: SensorInfo,
|
||||||
ListEntitiesSirenResponse: SirenInfo,
|
ListEntitiesSirenResponse: SirenInfo,
|
||||||
|
|
|
@ -41,6 +41,7 @@ from aioesphomeapi.api_pb2 import (
|
||||||
CameraImageResponse,
|
CameraImageResponse,
|
||||||
ClimateCommandRequest,
|
ClimateCommandRequest,
|
||||||
CoverCommandRequest,
|
CoverCommandRequest,
|
||||||
|
DateCommandRequest,
|
||||||
DeviceInfoResponse,
|
DeviceInfoResponse,
|
||||||
DisconnectResponse,
|
DisconnectResponse,
|
||||||
ExecuteServiceArgument,
|
ExecuteServiceArgument,
|
||||||
|
@ -617,6 +618,29 @@ async def test_number_command(
|
||||||
send.assert_called_once_with(NumberCommandRequest(**req))
|
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.asyncio
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"cmd, req",
|
"cmd, req",
|
||||||
|
|
|
@ -13,6 +13,7 @@ from aioesphomeapi.api_pb2 import (
|
||||||
BluetoothGATTGetServicesResponse,
|
BluetoothGATTGetServicesResponse,
|
||||||
ClimateStateResponse,
|
ClimateStateResponse,
|
||||||
CoverStateResponse,
|
CoverStateResponse,
|
||||||
|
DateStateResponse,
|
||||||
DeviceInfoResponse,
|
DeviceInfoResponse,
|
||||||
FanStateResponse,
|
FanStateResponse,
|
||||||
HomeassistantServiceMap,
|
HomeassistantServiceMap,
|
||||||
|
@ -23,6 +24,7 @@ from aioesphomeapi.api_pb2 import (
|
||||||
ListEntitiesButtonResponse,
|
ListEntitiesButtonResponse,
|
||||||
ListEntitiesClimateResponse,
|
ListEntitiesClimateResponse,
|
||||||
ListEntitiesCoverResponse,
|
ListEntitiesCoverResponse,
|
||||||
|
ListEntitiesDateResponse,
|
||||||
ListEntitiesFanResponse,
|
ListEntitiesFanResponse,
|
||||||
ListEntitiesLightResponse,
|
ListEntitiesLightResponse,
|
||||||
ListEntitiesLockResponse,
|
ListEntitiesLockResponse,
|
||||||
|
@ -69,6 +71,8 @@ from aioesphomeapi.model import (
|
||||||
ClimateState,
|
ClimateState,
|
||||||
CoverInfo,
|
CoverInfo,
|
||||||
CoverState,
|
CoverState,
|
||||||
|
DateInfo,
|
||||||
|
DateState,
|
||||||
DeviceInfo,
|
DeviceInfo,
|
||||||
FanInfo,
|
FanInfo,
|
||||||
FanState,
|
FanState,
|
||||||
|
@ -242,6 +246,8 @@ def test_api_version_ord():
|
||||||
(ClimateState, ClimateStateResponse),
|
(ClimateState, ClimateStateResponse),
|
||||||
(NumberInfo, ListEntitiesNumberResponse),
|
(NumberInfo, ListEntitiesNumberResponse),
|
||||||
(NumberState, NumberStateResponse),
|
(NumberState, NumberStateResponse),
|
||||||
|
(DateInfo, ListEntitiesDateResponse),
|
||||||
|
(DateState, DateStateResponse),
|
||||||
(SelectInfo, ListEntitiesSelectResponse),
|
(SelectInfo, ListEntitiesSelectResponse),
|
||||||
(SelectState, SelectStateResponse),
|
(SelectState, SelectStateResponse),
|
||||||
(HomeassistantServiceCall, HomeassistantServiceResponse),
|
(HomeassistantServiceCall, HomeassistantServiceResponse),
|
||||||
|
@ -358,6 +364,7 @@ def test_user_service_conversion():
|
||||||
FanInfo,
|
FanInfo,
|
||||||
LightInfo,
|
LightInfo,
|
||||||
NumberInfo,
|
NumberInfo,
|
||||||
|
DateInfo,
|
||||||
SelectInfo,
|
SelectInfo,
|
||||||
SensorInfo,
|
SensorInfo,
|
||||||
SirenInfo,
|
SirenInfo,
|
||||||
|
|
Loading…
Reference in New Issue