1
1
import logging
2
+ from abc import abstractmethod
2
3
from datetime import timedelta
3
4
from enum import Enum
4
5
from typing import Any , Optional
@@ -150,6 +151,11 @@ def normalized_name(self) -> str:
150
151
"""
151
152
return self .name .replace (":" , "_" ).replace ("-" , "_" )
152
153
154
+ @property
155
+ @abstractmethod
156
+ def unique_identifier (self ) -> str :
157
+ """Return unique identifier."""
158
+
153
159
154
160
class MiotAction (MiotBaseModel ):
155
161
"""Action presentation for miot."""
@@ -176,8 +182,6 @@ def fill_from_parent(self, service: "MiotService"):
176
182
177
183
def get_descriptor (self ):
178
184
"""Create a descriptor based on the property information."""
179
- id_ = self .name
180
-
181
185
extras = self .extras
182
186
extras ["urn" ] = self .urn
183
187
extras ["siid" ] = self .siid
@@ -190,12 +194,17 @@ def get_descriptor(self):
190
194
inputs = [prop .get_descriptor () for prop in self .inputs ]
191
195
192
196
return ActionDescriptor (
193
- id = id_ ,
197
+ id = self . unique_identifier ,
194
198
name = self .description ,
195
199
inputs = inputs ,
196
200
extras = extras ,
197
201
)
198
202
203
+ @property
204
+ def unique_identifier (self ) -> str :
205
+ """Return unique identifier."""
206
+ return f"{ self .normalized_name } _{ self .siid } _{ self .aiid } "
207
+
199
208
class Config :
200
209
extra = "forbid"
201
210
@@ -327,7 +336,7 @@ def _create_enum_descriptor(self) -> EnumDescriptor:
327
336
raise
328
337
329
338
desc = EnumDescriptor (
330
- id = self .name ,
339
+ id = self .unique_identifier ,
331
340
name = self .description ,
332
341
status_attribute = self .normalized_name ,
333
342
unit = self .unit ,
@@ -346,7 +355,7 @@ def _create_range_descriptor(
346
355
if self .range is None :
347
356
raise ValueError ("Range is None" )
348
357
desc = RangeDescriptor (
349
- id = self .name ,
358
+ id = self .unique_identifier ,
350
359
name = self .description ,
351
360
status_attribute = self .normalized_name ,
352
361
min_value = self .range [0 ],
@@ -363,14 +372,19 @@ def _create_range_descriptor(
363
372
def _create_regular_descriptor (self ) -> PropertyDescriptor :
364
373
"""Create boolean setting descriptor."""
365
374
return PropertyDescriptor (
366
- id = self .name ,
375
+ id = self .unique_identifier ,
367
376
name = self .description ,
368
377
status_attribute = self .normalized_name ,
369
378
type = self .format ,
370
379
extras = self .extras ,
371
380
access = self ._miot_access_list_to_access (self .access ),
372
381
)
373
382
383
+ @property
384
+ def unique_identifier (self ) -> str :
385
+ """Return unique identifier."""
386
+ return f"{ self .normalized_name } _{ self .siid } _{ self .piid } "
387
+
374
388
class Config :
375
389
extra = "forbid"
376
390
@@ -381,6 +395,11 @@ class MiotEvent(MiotBaseModel):
381
395
eiid : int = Field (alias = "iid" )
382
396
arguments : Any
383
397
398
+ @property
399
+ def unique_identifier (self ) -> str :
400
+ """Return unique identifier."""
401
+ return f"{ self .normalized_name } _{ self .siid } _{ self .eiid } "
402
+
384
403
class Config :
385
404
extra = "forbid"
386
405
0 commit comments