Add valve component (#852)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
b10cbd6c9a
commit
0ed69bbb30
|
@ -44,6 +44,7 @@ service APIConnection {
|
||||||
rpc siren_command (SirenCommandRequest) returns (void) {}
|
rpc siren_command (SirenCommandRequest) returns (void) {}
|
||||||
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 valve_command (ValveCommandRequest) returns (void) {}
|
||||||
rpc media_player_command (MediaPlayerCommandRequest) returns (void) {}
|
rpc media_player_command (MediaPlayerCommandRequest) returns (void) {}
|
||||||
rpc date_command (DateCommandRequest) returns (void) {}
|
rpc date_command (DateCommandRequest) returns (void) {}
|
||||||
rpc time_command (TimeCommandRequest) returns (void) {}
|
rpc time_command (TimeCommandRequest) returns (void) {}
|
||||||
|
@ -1718,3 +1719,52 @@ message TimeCommandRequest {
|
||||||
uint32 minute = 3;
|
uint32 minute = 3;
|
||||||
uint32 second = 4;
|
uint32 second = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==================== VALVE ====================
|
||||||
|
message ListEntitiesValveResponse {
|
||||||
|
option (id) = 109;
|
||||||
|
option (source) = SOURCE_SERVER;
|
||||||
|
option (ifdef) = "USE_VALVE";
|
||||||
|
|
||||||
|
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;
|
||||||
|
string device_class = 8;
|
||||||
|
|
||||||
|
bool assumed_state = 9;
|
||||||
|
bool supports_position = 10;
|
||||||
|
bool supports_stop = 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ValveOperation {
|
||||||
|
VALVE_OPERATION_IDLE = 0;
|
||||||
|
VALVE_OPERATION_IS_OPENING = 1;
|
||||||
|
VALVE_OPERATION_IS_CLOSING = 2;
|
||||||
|
}
|
||||||
|
message ValveStateResponse {
|
||||||
|
option (id) = 110;
|
||||||
|
option (source) = SOURCE_SERVER;
|
||||||
|
option (ifdef) = "USE_VALVE";
|
||||||
|
option (no_delay) = true;
|
||||||
|
|
||||||
|
fixed32 key = 1;
|
||||||
|
float position = 2;
|
||||||
|
ValveOperation current_operation = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ValveCommandRequest {
|
||||||
|
option (id) = 111;
|
||||||
|
option (source) = SOURCE_CLIENT;
|
||||||
|
option (ifdef) = "USE_VALVE";
|
||||||
|
option (no_delay) = true;
|
||||||
|
|
||||||
|
fixed32 key = 1;
|
||||||
|
bool has_position = 2;
|
||||||
|
float position = 3;
|
||||||
|
bool stop = 4;
|
||||||
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -67,6 +67,7 @@ from .api_pb2 import ( # type: ignore
|
||||||
TextCommandRequest,
|
TextCommandRequest,
|
||||||
TimeCommandRequest,
|
TimeCommandRequest,
|
||||||
UnsubscribeBluetoothLEAdvertisementsRequest,
|
UnsubscribeBluetoothLEAdvertisementsRequest,
|
||||||
|
ValveCommandRequest,
|
||||||
VoiceAssistantAudio,
|
VoiceAssistantAudio,
|
||||||
VoiceAssistantEventData,
|
VoiceAssistantEventData,
|
||||||
VoiceAssistantEventResponse,
|
VoiceAssistantEventResponse,
|
||||||
|
@ -1157,6 +1158,20 @@ class APIClient:
|
||||||
req.code = code
|
req.code = code
|
||||||
self._get_connection().send_message(req)
|
self._get_connection().send_message(req)
|
||||||
|
|
||||||
|
def valve_command(
|
||||||
|
self,
|
||||||
|
key: int,
|
||||||
|
position: float | None = None,
|
||||||
|
stop: bool = False,
|
||||||
|
) -> None:
|
||||||
|
req = ValveCommandRequest(key=key)
|
||||||
|
if position is not None:
|
||||||
|
req.has_position = True
|
||||||
|
req.position = position
|
||||||
|
if stop:
|
||||||
|
req.stop = stop
|
||||||
|
self._get_connection().send_message(req)
|
||||||
|
|
||||||
def media_player_command(
|
def media_player_command(
|
||||||
self,
|
self,
|
||||||
key: int,
|
key: int,
|
||||||
|
|
|
@ -77,6 +77,7 @@ from .api_pb2 import ( # type: ignore
|
||||||
ListEntitiesTextResponse,
|
ListEntitiesTextResponse,
|
||||||
ListEntitiesTextSensorResponse,
|
ListEntitiesTextSensorResponse,
|
||||||
ListEntitiesTimeResponse,
|
ListEntitiesTimeResponse,
|
||||||
|
ListEntitiesValveResponse,
|
||||||
LockCommandRequest,
|
LockCommandRequest,
|
||||||
LockStateResponse,
|
LockStateResponse,
|
||||||
MediaPlayerCommandRequest,
|
MediaPlayerCommandRequest,
|
||||||
|
@ -107,6 +108,8 @@ from .api_pb2 import ( # type: ignore
|
||||||
TimeCommandRequest,
|
TimeCommandRequest,
|
||||||
TimeStateResponse,
|
TimeStateResponse,
|
||||||
UnsubscribeBluetoothLEAdvertisementsRequest,
|
UnsubscribeBluetoothLEAdvertisementsRequest,
|
||||||
|
ValveCommandRequest,
|
||||||
|
ValveStateResponse,
|
||||||
VoiceAssistantAudio,
|
VoiceAssistantAudio,
|
||||||
VoiceAssistantEventResponse,
|
VoiceAssistantEventResponse,
|
||||||
VoiceAssistantRequest,
|
VoiceAssistantRequest,
|
||||||
|
@ -368,4 +371,7 @@ MESSAGE_TYPE_TO_PROTO = {
|
||||||
104: TimeStateResponse,
|
104: TimeStateResponse,
|
||||||
105: TimeCommandRequest,
|
105: TimeCommandRequest,
|
||||||
106: VoiceAssistantAudio,
|
106: VoiceAssistantAudio,
|
||||||
|
109: ListEntitiesValveResponse,
|
||||||
|
110: ValveStateResponse,
|
||||||
|
111: ValveCommandRequest,
|
||||||
}
|
}
|
||||||
|
|
|
@ -753,6 +753,31 @@ class LockEntityState(EntityState):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ==================== VALVE ====================
|
||||||
|
@_frozen_dataclass_decorator
|
||||||
|
class ValveInfo(EntityInfo):
|
||||||
|
device_class: str = ""
|
||||||
|
assumed_state: bool = False
|
||||||
|
supports_stop: bool = False
|
||||||
|
supports_position: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
class ValveOperation(APIIntEnum):
|
||||||
|
IDLE = 0
|
||||||
|
IS_OPENING = 1
|
||||||
|
IS_CLOSING = 2
|
||||||
|
|
||||||
|
|
||||||
|
@_frozen_dataclass_decorator
|
||||||
|
class ValveState(EntityState):
|
||||||
|
position: float = converter_field(
|
||||||
|
default=0.0, converter=fix_float_single_double_conversion
|
||||||
|
)
|
||||||
|
current_operation: ValveOperation | None = converter_field(
|
||||||
|
default=ValveOperation.IDLE, converter=ValveOperation.convert
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# ==================== MEDIA PLAYER ====================
|
# ==================== MEDIA PLAYER ====================
|
||||||
class MediaPlayerState(APIIntEnum):
|
class MediaPlayerState(APIIntEnum):
|
||||||
NONE = 0
|
NONE = 0
|
||||||
|
@ -868,6 +893,7 @@ COMPONENT_TYPE_TO_INFO: dict[str, type[EntityInfo]] = {
|
||||||
"alarm_control_panel": AlarmControlPanelInfo,
|
"alarm_control_panel": AlarmControlPanelInfo,
|
||||||
"text": TextInfo,
|
"text": TextInfo,
|
||||||
"time": TimeInfo,
|
"time": TimeInfo,
|
||||||
|
"valve": ValveInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1228,6 +1254,7 @@ _TYPE_TO_NAME = {
|
||||||
AlarmControlPanelInfo: "alarm_control_panel",
|
AlarmControlPanelInfo: "alarm_control_panel",
|
||||||
TextInfo: "text_info",
|
TextInfo: "text_info",
|
||||||
TimeInfo: "time",
|
TimeInfo: "time",
|
||||||
|
ValveInfo: "valve",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ from .api_pb2 import ( # type: ignore
|
||||||
ListEntitiesTextResponse,
|
ListEntitiesTextResponse,
|
||||||
ListEntitiesTextSensorResponse,
|
ListEntitiesTextSensorResponse,
|
||||||
ListEntitiesTimeResponse,
|
ListEntitiesTimeResponse,
|
||||||
|
ListEntitiesValveResponse,
|
||||||
LockStateResponse,
|
LockStateResponse,
|
||||||
MediaPlayerStateResponse,
|
MediaPlayerStateResponse,
|
||||||
NumberStateResponse,
|
NumberStateResponse,
|
||||||
|
@ -40,6 +41,7 @@ from .api_pb2 import ( # type: ignore
|
||||||
TextSensorStateResponse,
|
TextSensorStateResponse,
|
||||||
TextStateResponse,
|
TextStateResponse,
|
||||||
TimeStateResponse,
|
TimeStateResponse,
|
||||||
|
ValveStateResponse,
|
||||||
)
|
)
|
||||||
from .model import (
|
from .model import (
|
||||||
AlarmControlPanelEntityState,
|
AlarmControlPanelEntityState,
|
||||||
|
@ -80,6 +82,8 @@ from .model import (
|
||||||
TextState,
|
TextState,
|
||||||
TimeInfo,
|
TimeInfo,
|
||||||
TimeState,
|
TimeState,
|
||||||
|
ValveInfo,
|
||||||
|
ValveState,
|
||||||
)
|
)
|
||||||
|
|
||||||
SUBSCRIBE_STATES_RESPONSE_TYPES: dict[Any, type[EntityState]] = {
|
SUBSCRIBE_STATES_RESPONSE_TYPES: dict[Any, type[EntityState]] = {
|
||||||
|
@ -100,6 +104,7 @@ SUBSCRIBE_STATES_RESPONSE_TYPES: dict[Any, type[EntityState]] = {
|
||||||
MediaPlayerStateResponse: MediaPlayerEntityState,
|
MediaPlayerStateResponse: MediaPlayerEntityState,
|
||||||
AlarmControlPanelStateResponse: AlarmControlPanelEntityState,
|
AlarmControlPanelStateResponse: AlarmControlPanelEntityState,
|
||||||
TimeStateResponse: TimeState,
|
TimeStateResponse: TimeState,
|
||||||
|
ValveStateResponse: ValveState,
|
||||||
}
|
}
|
||||||
|
|
||||||
LIST_ENTITIES_SERVICES_RESPONSE_TYPES: dict[Any, type[EntityInfo] | None] = {
|
LIST_ENTITIES_SERVICES_RESPONSE_TYPES: dict[Any, type[EntityInfo] | None] = {
|
||||||
|
@ -123,4 +128,5 @@ LIST_ENTITIES_SERVICES_RESPONSE_TYPES: dict[Any, type[EntityInfo] | None] = {
|
||||||
ListEntitiesMediaPlayerResponse: MediaPlayerInfo,
|
ListEntitiesMediaPlayerResponse: MediaPlayerInfo,
|
||||||
ListEntitiesAlarmControlPanelResponse: AlarmControlPanelInfo,
|
ListEntitiesAlarmControlPanelResponse: AlarmControlPanelInfo,
|
||||||
ListEntitiesTimeResponse: TimeInfo,
|
ListEntitiesTimeResponse: TimeInfo,
|
||||||
|
ListEntitiesValveResponse: ValveInfo,
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,7 @@ from aioesphomeapi.api_pb2 import (
|
||||||
SwitchCommandRequest,
|
SwitchCommandRequest,
|
||||||
TextCommandRequest,
|
TextCommandRequest,
|
||||||
TimeCommandRequest,
|
TimeCommandRequest,
|
||||||
|
ValveCommandRequest,
|
||||||
VoiceAssistantAudio,
|
VoiceAssistantAudio,
|
||||||
VoiceAssistantAudioSettings,
|
VoiceAssistantAudioSettings,
|
||||||
VoiceAssistantEventData,
|
VoiceAssistantEventData,
|
||||||
|
@ -692,6 +693,49 @@ async def test_lock_command(
|
||||||
send.assert_called_once_with(LockCommandRequest(**req))
|
send.assert_called_once_with(LockCommandRequest(**req))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"cmd, req",
|
||||||
|
[
|
||||||
|
(dict(key=1), dict(key=1)),
|
||||||
|
(dict(key=1, position=1.0),),
|
||||||
|
(dict(key=1, position=0.0),),
|
||||||
|
(dict(key=1, stop=True),),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_valve_command(
|
||||||
|
auth_client: APIClient, cmd: dict[str, Any], req: dict[str, Any]
|
||||||
|
) -> None:
|
||||||
|
send = patch_send(auth_client)
|
||||||
|
|
||||||
|
auth_client.valve_command(**cmd)
|
||||||
|
send.assert_called_once_with(ValveCommandRequest(**req))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"cmd, req",
|
||||||
|
[
|
||||||
|
(dict(key=1), dict(key=1)),
|
||||||
|
(dict(key=1, position=0.5), dict(key=1, has_position=True, position=0.5)),
|
||||||
|
(dict(key=1, position=0.0), dict(key=1, has_position=True, position=0.0)),
|
||||||
|
(dict(key=1, stop=True), dict(key=1, stop=True)),
|
||||||
|
(
|
||||||
|
dict(key=1, position=1.0),
|
||||||
|
dict(key=1, has_position=True, position=1.0),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_valve_command(
|
||||||
|
auth_client: APIClient, cmd: dict[str, Any], req: dict[str, Any]
|
||||||
|
) -> None:
|
||||||
|
send = patch_send(auth_client)
|
||||||
|
patch_api_version(auth_client, APIVersion(1, 1))
|
||||||
|
|
||||||
|
auth_client.valve_command(**cmd)
|
||||||
|
send.assert_called_once_with(ValveCommandRequest(**req))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"cmd, req",
|
"cmd, req",
|
||||||
|
@ -2443,6 +2487,7 @@ async def test_calls_after_connection_closed(
|
||||||
client.cover_command,
|
client.cover_command,
|
||||||
client.fan_command,
|
client.fan_command,
|
||||||
client.light_command,
|
client.light_command,
|
||||||
|
client.valve_command,
|
||||||
client.media_player_command,
|
client.media_player_command,
|
||||||
client.siren_command,
|
client.siren_command,
|
||||||
):
|
):
|
||||||
|
|
|
@ -37,6 +37,7 @@ from aioesphomeapi.api_pb2 import (
|
||||||
ListEntitiesSwitchResponse,
|
ListEntitiesSwitchResponse,
|
||||||
ListEntitiesTextSensorResponse,
|
ListEntitiesTextSensorResponse,
|
||||||
ListEntitiesTimeResponse,
|
ListEntitiesTimeResponse,
|
||||||
|
ListEntitiesValveResponse,
|
||||||
LockStateResponse,
|
LockStateResponse,
|
||||||
MediaPlayerStateResponse,
|
MediaPlayerStateResponse,
|
||||||
NumberStateResponse,
|
NumberStateResponse,
|
||||||
|
@ -47,6 +48,7 @@ from aioesphomeapi.api_pb2 import (
|
||||||
TextSensorStateResponse,
|
TextSensorStateResponse,
|
||||||
TextStateResponse,
|
TextStateResponse,
|
||||||
TimeStateResponse,
|
TimeStateResponse,
|
||||||
|
ValveStateResponse,
|
||||||
)
|
)
|
||||||
from aioesphomeapi.model import (
|
from aioesphomeapi.model import (
|
||||||
_TYPE_TO_NAME,
|
_TYPE_TO_NAME,
|
||||||
|
@ -105,6 +107,8 @@ from aioesphomeapi.model import (
|
||||||
UserService,
|
UserService,
|
||||||
UserServiceArg,
|
UserServiceArg,
|
||||||
UserServiceArgType,
|
UserServiceArgType,
|
||||||
|
ValveInfo,
|
||||||
|
ValveState,
|
||||||
VoiceAssistantFeature,
|
VoiceAssistantFeature,
|
||||||
build_unique_id,
|
build_unique_id,
|
||||||
converter_field,
|
converter_field,
|
||||||
|
@ -261,6 +265,8 @@ def test_api_version_ord():
|
||||||
(ButtonInfo, ListEntitiesButtonResponse),
|
(ButtonInfo, ListEntitiesButtonResponse),
|
||||||
(LockInfo, ListEntitiesLockResponse),
|
(LockInfo, ListEntitiesLockResponse),
|
||||||
(LockEntityState, LockStateResponse),
|
(LockEntityState, LockStateResponse),
|
||||||
|
(ValveInfo, ListEntitiesValveResponse),
|
||||||
|
(ValveState, ValveStateResponse),
|
||||||
(MediaPlayerInfo, ListEntitiesMediaPlayerResponse),
|
(MediaPlayerInfo, ListEntitiesMediaPlayerResponse),
|
||||||
(MediaPlayerEntityState, MediaPlayerStateResponse),
|
(MediaPlayerEntityState, MediaPlayerStateResponse),
|
||||||
(AlarmControlPanelInfo, ListEntitiesAlarmControlPanelResponse),
|
(AlarmControlPanelInfo, ListEntitiesAlarmControlPanelResponse),
|
||||||
|
@ -380,6 +386,7 @@ def test_user_service_conversion():
|
||||||
CameraInfo,
|
CameraInfo,
|
||||||
ClimateInfo,
|
ClimateInfo,
|
||||||
LockInfo,
|
LockInfo,
|
||||||
|
ValveInfo,
|
||||||
MediaPlayerInfo,
|
MediaPlayerInfo,
|
||||||
AlarmControlPanelInfo,
|
AlarmControlPanelInfo,
|
||||||
TextInfo,
|
TextInfo,
|
||||||
|
|
Loading…
Reference in New Issue