mirror of
				https://github.com/XiaoMi/ha_xiaomi_home.git
				synced 2025-11-04 19:32:07 +08:00 
			
		
		
		
	feat: avoid setting icon when device_class is defined (#855)
This commit is contained in:
		@@ -591,13 +591,8 @@ class MIoTDevice:
 | 
				
			|||||||
            # Priority: spec_modify.unit > unit_convert > specv2entity.unit
 | 
					            # Priority: spec_modify.unit > unit_convert > specv2entity.unit
 | 
				
			||||||
            miot_prop.external_unit = SPEC_PROP_TRANS_MAP['properties'][
 | 
					            miot_prop.external_unit = SPEC_PROP_TRANS_MAP['properties'][
 | 
				
			||||||
                prop_name]['unit_of_measurement']
 | 
					                prop_name]['unit_of_measurement']
 | 
				
			||||||
        if (
 | 
					        # Priority: default.icon when device_class is set > spec_modify.icon
 | 
				
			||||||
            not miot_prop.icon
 | 
					        #           > icon_convert
 | 
				
			||||||
            and 'icon' in SPEC_PROP_TRANS_MAP['properties'][prop_name]
 | 
					 | 
				
			||||||
        ):
 | 
					 | 
				
			||||||
            # Priority: spec_modify.icon > icon_convert > specv2entity.icon
 | 
					 | 
				
			||||||
            miot_prop.icon = SPEC_PROP_TRANS_MAP['properties'][prop_name][
 | 
					 | 
				
			||||||
                'icon']
 | 
					 | 
				
			||||||
        miot_prop.platform = platform
 | 
					        miot_prop.platform = platform
 | 
				
			||||||
        return True
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -88,7 +88,7 @@ class Number(MIoTPropertyEntity, NumberEntity):
 | 
				
			|||||||
        if self.spec.external_unit:
 | 
					        if self.spec.external_unit:
 | 
				
			||||||
            self._attr_native_unit_of_measurement = self.spec.external_unit
 | 
					            self._attr_native_unit_of_measurement = self.spec.external_unit
 | 
				
			||||||
        # Set icon
 | 
					        # Set icon
 | 
				
			||||||
        if self.spec.icon:
 | 
					        if self.spec.icon and not self.device_class:
 | 
				
			||||||
            self._attr_icon = self.spec.icon
 | 
					            self._attr_icon = self.spec.icon
 | 
				
			||||||
        # Set value range
 | 
					        # Set value range
 | 
				
			||||||
        if self._value_range:
 | 
					        if self._value_range:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -116,7 +116,7 @@ class Sensor(MIoTPropertyEntity, SensorEntity):
 | 
				
			|||||||
            if spec.state_class:
 | 
					            if spec.state_class:
 | 
				
			||||||
                self._attr_state_class = spec.state_class
 | 
					                self._attr_state_class = spec.state_class
 | 
				
			||||||
        # Set icon
 | 
					        # Set icon
 | 
				
			||||||
        if spec.icon:
 | 
					        if spec.icon and not self.device_class:
 | 
				
			||||||
            self._attr_icon = spec.icon
 | 
					            self._attr_icon = spec.icon
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user