mirror of
				https://github.com/XiaoMi/ha_xiaomi_home.git
				synced 2025-10-31 01:12:05 +08:00 
			
		
		
		
	feat: add entity_category for indicator-light (#697)
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				Tests / check-rule-format (push) Has been cancelled
				
			
		
			
				
	
				Validate / validate-hassfest (push) Has been cancelled
				
			
		
			
				
	
				Validate / validate-hacs (push) Has been cancelled
				
			
		
			
				
	
				Validate / validate-lint (push) Has been cancelled
				
			
		
			
				
	
				Validate / validate-setup (push) Has been cancelled
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	Tests / check-rule-format (push) Has been cancelled
				
			Validate / validate-hassfest (push) Has been cancelled
				
			Validate / validate-hacs (push) Has been cancelled
				
			Validate / validate-lint (push) Has been cancelled
				
			Validate / validate-setup (push) Has been cancelled
				
			This commit is contained in:
		| @@ -549,6 +549,10 @@ class MIoTDevice: | |||||||
|         # Optional actions |         # Optional actions | ||||||
|         # Optional events |         # Optional events | ||||||
|         miot_service.platform = platform |         miot_service.platform = platform | ||||||
|  |         # entity_category | ||||||
|  |         if entity_category := SPEC_SERVICE_TRANS_MAP[service_name].get( | ||||||
|  |             'entity_category', None): | ||||||
|  |             miot_service.entity_category = entity_category | ||||||
|         return entity_data |         return entity_data | ||||||
|  |  | ||||||
|     def parse_miot_property_entity(self, miot_prop: MIoTSpecProperty) -> bool: |     def parse_miot_property_entity(self, miot_prop: MIoTSpecProperty) -> bool: | ||||||
| @@ -899,6 +903,7 @@ class MIoTServiceEntity(Entity): | |||||||
|             self._attr_name = ( |             self._attr_name = ( | ||||||
|                 f'{"* "if self.entity_data.spec.proprietary else " "}' |                 f'{"* "if self.entity_data.spec.proprietary else " "}' | ||||||
|                 f'{self.entity_data.spec.description_trans}') |                 f'{self.entity_data.spec.description_trans}') | ||||||
|  |             self._attr_entity_category = entity_data.spec.entity_category | ||||||
|         # Set entity attr |         # Set entity attr | ||||||
|         self._attr_unique_id = self.entity_id |         self._attr_unique_id = self.entity_id | ||||||
|         self._attr_should_poll = False |         self._attr_should_poll = False | ||||||
|   | |||||||
| @@ -465,7 +465,7 @@ class _MIoTSpecBase: | |||||||
|     iid: int |     iid: int | ||||||
|     type_: str |     type_: str | ||||||
|     description: str |     description: str | ||||||
|     description_trans: str |     description_trans: Optional[str] | ||||||
|     proprietary: bool |     proprietary: bool | ||||||
|     need_filter: bool |     need_filter: bool | ||||||
|     name: str |     name: str | ||||||
| @@ -476,6 +476,7 @@ class _MIoTSpecBase: | |||||||
|     device_class: Any |     device_class: Any | ||||||
|     state_class: Any |     state_class: Any | ||||||
|     external_unit: Any |     external_unit: Any | ||||||
|  |     entity_category: Optional[str] | ||||||
|  |  | ||||||
|     spec_id: int |     spec_id: int | ||||||
|  |  | ||||||
| @@ -494,6 +495,7 @@ class _MIoTSpecBase: | |||||||
|         self.device_class = None |         self.device_class = None | ||||||
|         self.state_class = None |         self.state_class = None | ||||||
|         self.external_unit = None |         self.external_unit = None | ||||||
|  |         self.entity_category = None | ||||||
|  |  | ||||||
|         self.spec_id = hash(f'{self.type_}.{self.iid}') |         self.spec_id = hash(f'{self.type_}.{self.iid}') | ||||||
|  |  | ||||||
|   | |||||||
| @@ -51,6 +51,7 @@ from homeassistant.components.event import EventDeviceClass | |||||||
|  |  | ||||||
| from homeassistant.const import ( | from homeassistant.const import ( | ||||||
|     CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, |     CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, | ||||||
|  |     EntityCategory, | ||||||
|     LIGHT_LUX, |     LIGHT_LUX, | ||||||
|     UnitOfEnergy, |     UnitOfEnergy, | ||||||
|     UnitOfPower, |     UnitOfPower, | ||||||
| @@ -330,7 +331,8 @@ SPEC_DEVICE_TRANS_MAP: dict = { | |||||||
|             'events': set<event instance name: str>, |             'events': set<event instance name: str>, | ||||||
|             'actions': set<action instance name: str> |             'actions': set<action instance name: str> | ||||||
|         }, |         }, | ||||||
|         'entity': str |         'entity': str, | ||||||
|  |         'entity_category'?: str | ||||||
|     } |     } | ||||||
| } | } | ||||||
| """ | """ | ||||||
| @@ -348,10 +350,23 @@ SPEC_SERVICE_TRANS_MAP: dict = { | |||||||
|         }, |         }, | ||||||
|         'entity': 'light' |         'entity': 'light' | ||||||
|     }, |     }, | ||||||
|     'indicator-light': 'light', |  | ||||||
|     'ambient-light': 'light', |     'ambient-light': 'light', | ||||||
|     'night-light': 'light', |     'night-light': 'light', | ||||||
|     'white-light': 'light', |     'white-light': 'light', | ||||||
|  |     'indicator-light': { | ||||||
|  |         'required': { | ||||||
|  |             'properties': { | ||||||
|  |                 'on': {'read', 'write'} | ||||||
|  |             } | ||||||
|  |         }, | ||||||
|  |         'optional': { | ||||||
|  |             'properties': { | ||||||
|  |                 'mode', 'brightness', | ||||||
|  |             } | ||||||
|  |         }, | ||||||
|  |         'entity': 'light', | ||||||
|  |         'entity_category': EntityCategory.CONFIG | ||||||
|  |     }, | ||||||
|     'fan': { |     'fan': { | ||||||
|         'required': { |         'required': { | ||||||
|             'properties': { |             'properties': { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user