Skip to content

Commit c538291

Browse files
committed
Add model converter
1 parent 1d39bf8 commit c538291

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

aioesphomeapi/model.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@ class VoiceAssistantSubscriptionFlag(enum.IntFlag):
133133
API_AUDIO = 1 << 2
134134

135135

136+
class SubDeviceInfo(APIModelBase):
137+
id: str = ""
138+
name: str = ""
139+
suggested_area: str = ""
140+
141+
@classmethod
142+
def convert_list(cls, value: list[Any]) -> list[SubDeviceInfo]:
143+
ret = []
144+
for x in value:
145+
if isinstance(x, dict):
146+
ret.append(SubDeviceInfo.from_dict(x))
147+
else:
148+
ret.append(SubDeviceInfo.from_pb(x))
149+
return ret
150+
151+
136152
@_frozen_dataclass_decorator
137153
class DeviceInfo(APIModelBase):
138154
uses_password: bool = False
@@ -153,6 +169,7 @@ class DeviceInfo(APIModelBase):
153169
bluetooth_proxy_feature_flags: int = 0
154170
suggested_area: str = ""
155171
bluetooth_mac_address: str = ""
172+
sub_devices: list[SubDeviceInfo] = converter_field(default_factory=list, converter=SubDeviceInfo.convert_list)
156173

157174
def bluetooth_proxy_feature_flags_compat(self, api_version: APIVersion) -> int:
158175
if api_version < APIVersion(1, 9):
@@ -198,6 +215,8 @@ class EntityInfo(APIModelBase):
198215
entity_category: EntityCategory | None = converter_field(
199216
default=EntityCategory.NONE, converter=EntityCategory.convert
200217
)
218+
# # Is it ok to ad for the generic device info before all are added?
219+
# device_id: str = ""
201220

202221

203222
@_frozen_dataclass_decorator
@@ -210,6 +229,7 @@ class EntityState(APIModelBase):
210229
class BinarySensorInfo(EntityInfo):
211230
device_class: str = ""
212231
is_status_binary_sensor: bool = False
232+
device_id: str = ""
213233

214234

215235
@_frozen_dataclass_decorator
@@ -226,6 +246,7 @@ class CoverInfo(EntityInfo):
226246
supports_position: bool = False
227247
supports_tilt: bool = False
228248
device_class: str = ""
249+
device_id: str = ""
229250

230251

231252
class LegacyCoverState(APIIntEnum):

0 commit comments

Comments
 (0)