@@ -1335,12 +1335,8 @@ def turn_off(self, **kwargs):
13351335
13361336 def _update_sub_entities (self , properties , services = None , domain = None , option = None , ** kwargs ):
13371337 actions = kwargs .get ('actions' , [])
1338- from .sensor import MiotSensorSubEntity
1339- from .binary_sensor import MiotBinarySensorSubEntity
1340- from .switch import MiotSwitchSubEntity
13411338 from .light import MiotLightSubEntity
1342- from .fan import (MiotFanSubEntity , MiotModesSubEntity )
1343- from .cover import MiotCoverSubEntity
1339+ from .fan import MiotFanSubEntity
13441340 if isinstance (services , MiotService ):
13451341 sls = [services ]
13461342 elif services == '*' :
@@ -1351,17 +1347,8 @@ def _update_sub_entities(self, properties, services=None, domain=None, option=No
13511347 sls = [properties .service ]
13521348 else :
13531349 sls = [self ._miot_service ]
1354- add_sensors = self ._add_entities .get ('sensor' )
1355- add_binary_sensors = self ._add_entities .get ('binary_sensor' )
1356- add_switches = self ._add_entities .get ('switch' )
13571350 add_lights = self ._add_entities .get ('light' )
13581351 add_fans = self ._add_entities .get ('fan' )
1359- add_covers = self ._add_entities .get ('cover' )
1360- add_numbers = self ._add_entities .get ('number' )
1361- add_selects = self ._add_entities .get ('select' )
1362- add_buttons = self ._add_entities .get ('button' )
1363- add_texts = self ._add_entities .get ('text' )
1364- add_device_trackers = self ._add_entities .get ('device_tracker' )
13651352 exclude_services = self ._state_attrs .get ('exclude_miot_services' ) or []
13661353 for s in sls :
13671354 if s .name in exclude_services :
@@ -1390,88 +1377,6 @@ def _update_sub_entities(self, properties, services=None, domain=None, option=No
13901377 if new and fnm in self ._subs :
13911378 self ._check_same_sub_entity (fnm , domain , add = 1 )
13921379 self .logger .debug ('%s: Added sub entity %s: %s' , self .name_model , domain , fnm )
1393- continue
1394- pls = []
1395- if isinstance (properties , MiotProperty ):
1396- pls = [properties ]
1397- if properties :
1398- pls .extend (s .get_properties (* cv .ensure_list (properties )))
1399- if actions :
1400- pls .extend (s .get_actions (* cv .ensure_list (actions )))
1401- for p in pls :
1402- fnm = p .unique_name
1403- opt = {
1404- 'unique_id' : f'{ self .unique_did } -{ fnm } ' ,
1405- ** (option or {}),
1406- }
1407- tms = self ._check_same_sub_entity (fnm , domain )
1408- new = True
1409- if fnm in self ._subs :
1410- new = False
1411- self ._subs [fnm ].update_from_parent ()
1412- self ._check_same_sub_entity (fnm , domain , add = 1 )
1413- elif tms > 0 :
1414- if tms <= 1 :
1415- self .logger .info ('%s: Device sub entity %s: %s already exists.' , self .name_model , domain , fnm )
1416- elif isinstance (p , MiotAction ):
1417- """migrate to converter"""
1418- elif add_buttons and domain == 'button' and (p .value_list or p .is_bool ):
1419- from .button import MiotButtonSubEntity
1420- nls = []
1421- f = fnm
1422- for pv in p .value_list :
1423- vk = pv .get ('value' )
1424- f = f'{ fnm } -{ vk } '
1425- if f in self ._subs :
1426- new = False
1427- continue
1428- self ._subs [f ] = MiotButtonSubEntity (self , p , vk , option = opt )
1429- nls .append (self ._subs [f ])
1430- if p .is_bool :
1431- self ._subs [f ] = MiotButtonSubEntity (self , p , True , option = opt )
1432- nls .append (self ._subs [f ])
1433- if nls :
1434- add_buttons (nls , update_before_add = True )
1435- new = True
1436- fnm = f
1437- elif p .full_name not in self ._state_attrs and not p .writeable and not kwargs .get ('whatever' ):
1438- continue
1439- elif add_switches and domain == 'switch' and (p .format in ['bool' , 'uint8' ]) and p .writeable :
1440- self ._subs [fnm ] = MiotSwitchSubEntity (self , p , option = opt )
1441- add_switches ([self ._subs [fnm ]], update_before_add = True )
1442- elif add_binary_sensors and domain == 'binary_sensor' and (p .is_bool or p .is_integer ):
1443- self ._subs [fnm ] = MiotBinarySensorSubEntity (self , p , option = opt )
1444- add_binary_sensors ([self ._subs [fnm ]], update_before_add = True )
1445- elif add_sensors and domain == 'sensor' :
1446- if p .full_name == self ._state_attrs .get ('state_property' ):
1447- continue
1448- self ._subs [fnm ] = MiotSensorSubEntity (self , p , option = opt )
1449- add_sensors ([self ._subs [fnm ]], update_before_add = True )
1450- elif add_fans and domain == 'fan' :
1451- self ._subs [fnm ] = MiotModesSubEntity (self , p , option = opt )
1452- add_fans ([self ._subs [fnm ]], update_before_add = True )
1453- elif add_covers and domain == 'cover' :
1454- self ._subs [fnm ] = MiotCoverSubEntity (self , p , option = opt )
1455- add_covers ([self ._subs [fnm ]], update_before_add = True )
1456- elif add_numbers and domain in ['number' , 'number_select' ] and p .value_range :
1457- from .number import MiotNumberSubEntity
1458- self ._subs [fnm ] = MiotNumberSubEntity (self , p , option = opt )
1459- add_numbers ([self ._subs [fnm ]], update_before_add = True )
1460- elif add_selects and domain in ['select' , 'number_select' ] and (p .value_list or p .value_range ):
1461- from .select import MiotSelectSubEntity
1462- self ._subs [fnm ] = MiotSelectSubEntity (self , p , option = opt )
1463- add_selects ([self ._subs [fnm ]], update_before_add = True )
1464- elif add_texts and domain == 'text' and p .writeable :
1465- from .text import MiotTextSubEntity
1466- self ._subs [fnm ] = MiotTextSubEntity (self , p , option = opt )
1467- add_texts ([self ._subs [fnm ]], update_before_add = True )
1468- elif add_device_trackers and domain == 'scanner' and (p .is_bool or p .is_integer ):
1469- from .device_tracker import MiotScannerSubEntity
1470- self ._subs [fnm ] = MiotScannerSubEntity (self , p , option = opt )
1471- add_device_trackers ([self ._subs [fnm ]], update_before_add = True )
1472- if new and fnm in self ._subs :
1473- self ._check_same_sub_entity (fnm , domain , add = 1 )
1474- self .logger .debug ('%s: Added sub entity %s: %s' , self .name_model , domain , fnm )
14751380
14761381 async def async_get_device_data (self , key , did = None , throw = False , ** kwargs ):
14771382 if did is None :
0 commit comments