Skip to content

Commit 92c7699

Browse files
authored
feat: Add Select Entity support (unfoldedcircle#44)
1 parent f5b1f0e commit 92c7699

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

ucapi/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from .light import Light # noqa: F401
4545
from .media_player import MediaPlayer # noqa: F401
4646
from .remote import Remote # noqa: F401
47+
from .select import Select # noqa: F401
4748
from .sensor import Sensor # noqa: F401
4849
from .switch import Switch # noqa: F401
4950
from .voice_assistant import VoiceAssistant # noqa: F401

ucapi/entity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class EntityTypes(str, Enum):
2525
LIGHT = "light"
2626
MEDIA_PLAYER = "media_player"
2727
REMOTE = "remote"
28+
SELECT = "select"
2829
SENSOR = "sensor"
2930
SWITCH = "switch"
3031
IR_EMITTER = "ir_emitter"

ucapi/select.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
"""
2+
Switch entity definitions.
3+
4+
:copyright: (c) 2023 by Unfolded Circle ApS.
5+
:license: MPL-2.0, see LICENSE for more details.
6+
"""
7+
8+
from enum import Enum
9+
from typing import Any
10+
11+
from .api_definitions import CommandHandler
12+
from .entity import Entity, EntityTypes
13+
14+
15+
class States(str, Enum):
16+
"""Select entity states."""
17+
18+
UNAVAILABLE = "UNAVAILABLE"
19+
UNKNOWN = "UNKNOWN"
20+
ON = "ON"
21+
22+
23+
class Features(str, Enum):
24+
"""Select entity features."""
25+
26+
27+
class Attributes(str, Enum):
28+
"""Select entity attributes."""
29+
30+
STATE = "state"
31+
CURRENT_OPTION = "current_option"
32+
OPTIONS = "options"
33+
34+
35+
class Commands(str, Enum):
36+
"""Select entity commands."""
37+
38+
SELECT_OPTION = "select_option"
39+
SELECT_FIRST = "select_first"
40+
SELECT_LAST = "select_last"
41+
SELECT_NEXT = "select_next"
42+
SELECT_PREVIOUS = "select_previous"
43+
44+
45+
class DeviceClasses(str, Enum):
46+
"""Select entity device classes."""
47+
48+
49+
class Options(str, Enum):
50+
"""Select entity options."""
51+
52+
53+
class Select(Entity):
54+
"""
55+
Select entity class.
56+
57+
See https://github.com/unfoldedcircle/core-api/blob/main/doc/entities/entity_select.md
58+
for more information.
59+
"""
60+
61+
# pylint: disable=R0917
62+
def __init__(
63+
self,
64+
identifier: str,
65+
name: str | dict[str, str],
66+
attributes: dict[str, Any],
67+
*,
68+
area: str | None = None,
69+
cmd_handler: CommandHandler = None,
70+
):
71+
"""
72+
Create select-entity instance.
73+
74+
:param identifier: entity identifier
75+
:param name: friendly name
76+
:param attributes: select attributes
77+
:param area: optional area
78+
:param cmd_handler: handler for entity commands
79+
"""
80+
super().__init__(
81+
identifier,
82+
name,
83+
EntityTypes.SELECT,
84+
[],
85+
attributes,
86+
area=area,
87+
cmd_handler=cmd_handler,
88+
)

0 commit comments

Comments
 (0)