Merge pull request #106 from Cyborg2017/staging

Minor fixes and improvements
This commit is contained in:
Yingqi Tang
2026-02-04 15:59:01 +08:00
committed by GitHub
10 changed files with 747 additions and 79 deletions

View File

@@ -1,5 +1,5 @@
from homeassistant.components.fan import DIRECTION_FORWARD, DIRECTION_REVERSE
from homeassistant.const import Platform, UnitOfTemperature, PRECISION_WHOLE
from homeassistant.const import Platform, UnitOfTemperature, UnitOfTime, PRECISION_WHOLE
DEVICE_MAPPING = {
"default": {
@@ -11,7 +11,12 @@ DEVICE_MAPPING = {
"light": {
"power": "power",
"brightness": {"brightness": [1, 100]},
"color_temp": {"color_temperature": [3000, 5700]}, # 添加色温配置
"color_temp": {
"color_temperature": {
"kelvin_range": [3000, 5700],
"device_range": [0, 100]
}
},
"preset_modes": {
"night": {"scene_light": "night"},
"read": {"scene_light": "read"},
@@ -33,7 +38,12 @@ DEVICE_MAPPING = {
"light": {
"power": "led_power",
"brightness": {"brightness": [1, 100]},
"color_temp": {"color_temperature": [2700, 6500]},
"color_temp": {
"color_temperature": {
"kelvin_range": [2700, 6500],
"device_range": [0, 100]
}
},
"preset_modes": {
"work": {"led_scene_light": "work"},
"eating": {"led_scene_light": "eating"},
@@ -82,7 +92,12 @@ DEVICE_MAPPING = {
"light": {
"power": "led_power",
"brightness": {"brightness": [1, 100]},
"color_temp": {"color_temperature": [2700, 6500]},
"color_temp": {
"color_temperature": {
"kelvin_range": [2700, 6500],
"device_range": [0, 100]
}
},
"preset_modes": {
"work": {"led_scene_light": "work"},
"eating": {"led_scene_light": "eating"},
@@ -126,5 +141,40 @@ DEVICE_MAPPING = {
}
}
}
},
"22222222": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [],
"entities": {
Platform.LIGHT: {
"light": {
"power": "power",
"brightness": {"brightness": [0, 255]},
"color_temp": {
"color_temperature": {
"kelvin_range": [2700, 6500],
"device_range": [0, 255]
}
},
"preset_modes": {
"night": {"scene_light": "night"},
"read": {"scene_light": "read"},
"mild": {"scene_light": "mild"},
"life": {"scene_light": "life"},
"film": {"scene_light": "film"},
"manual": {"scene_light": "manual"},
}
}
},
Platform.NUMBER: {
"delay_light_off": {
"min": 0,
"max": 60,
"step": 1,
"unit_of_measurement": UnitOfTime.MINUTES
}
}
}
}
}

View File

@@ -1125,5 +1125,155 @@ DEVICE_MAPPING = {
}
}
}
},
("22012369", "22040023", "22270043"): {
"rationale": ["off", "on"],
"queries": [{}, {"query_type": "run_status"}, {"query_type": "indoor_temperature"}],
"centralized": ["power", "temperature", "mode", "eco", "comfort_power_save",
"wind_swing_lr", "wind_swing_ud", "wind_speed", "ptc", "dry"],
"entities": {
Platform.CLIMATE: {
"thermostat": {
"power": "power",
"hvac_modes": {
"off": {"power": "off"},
"heat": {"power": "on", "mode": "heat"},
"cool": {"power": "on", "mode": "cool"},
"auto": {"power": "on", "mode": "auto"},
"dry": {"power": "on", "mode": "dry"},
"fan_only": {"power": "on", "mode": "fan"}
},
"preset_modes": {
"none": {
"eco": "off",
"comfort_power_save": "off"
},
"eco": {"eco": "on"},
"comfort": {"comfort_power_save": "on"}
},
"swing_modes": {
"off": {"wind_swing_lr": "off", "wind_swing_ud": "off"},
"both": {"wind_swing_lr": "on", "wind_swing_ud": "on"},
"horizontal": {"wind_swing_lr": "on", "wind_swing_ud": "off"},
"vertical": {"wind_swing_lr": "off", "wind_swing_ud": "on"},
},
"fan_modes": {
"silent": {"wind_speed": 20},
"low": {"wind_speed": 40},
"medium": {"wind_speed": 60},
"high": {"wind_speed": 80},
"full": {"wind_speed": 100},
"auto": {"wind_speed": 102}
},
"target_temperature": ["temperature", "small_temperature"],
"current_temperature": "indoor_temperature",
"pre_mode": "mode",
"aux_heat": "ptc",
"min_temp": 17,
"max_temp": 30,
"temperature_unit": UnitOfTemperature.CELSIUS,
"precision": PRECISION_HALVES,
}
},
Platform.SWITCH: {
"dry": {
"device_class": SwitchDeviceClass.SWITCH,
},
"ptc": {
"device_class": SwitchDeviceClass.SWITCH,
"translation_key": "aux_heat",
}
},
Platform.SENSOR: {
"mode": {
"device_class": SensorDeviceClass.ENUM,
},
"indoor_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"outdoor_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
}
}
}
},
"22251077": {
"rationale": ["off", "on"],
"queries": [{}, {"query_type": "run_status"}, {"query_type": "indoor_temperature"}],
"centralized": ["power", "temperature", "mode", "eco", "comfort_power_save",
"wind_swing_lr", "wind_swing_lr_under", "wind_swing_ud", "wind_speed", "ptc", "dry"],
"entities": {
Platform.CLIMATE: {
"thermostat": {
"power": "power",
"hvac_modes": {
"off": {"power": "off"},
"heat": {"power": "on", "mode": "heat"},
"cool": {"power": "on", "mode": "cool"},
"auto": {"power": "on", "mode": "auto"},
"dry": {"power": "on", "mode": "dry"},
"fan_only": {"power": "on", "mode": "fan"}
},
"preset_modes": {
"none": {"eco": "off"},
"eco": {"eco": "on"}
},
"swing_modes": {
"off": {"wind_swing_lr": "off", "wind_swing_lr_under": "off", "wind_swing_ud": "off"},
"both": {"wind_swing_lr": "on", "wind_swing_lr_under": "on", "wind_swing_ud": "on"},
"horizontal_upper_only": {"wind_swing_lr": "on", "wind_swing_lr_under": "off", "wind_swing_ud": "off"},
"horizontal_under_only": {"wind_swing_lr": "off", "wind_swing_lr_under": "on", "wind_swing_ud": "off"},
"horizontal_upper_under": {"wind_swing_lr": "on", "wind_swing_lr_under": "on", "wind_swing_ud": "off"},
"horizontal_upper_vertical": {"wind_swing_lr": "on", "wind_swing_lr_under": "off", "wind_swing_ud": "on"},
"horizontal_under_vertical": {"wind_swing_lr": "off", "wind_swing_lr_under": "on", "wind_swing_ud": "on"},
"vertical_only": {"wind_swing_lr": "off", "wind_swing_lr_under": "off", "wind_swing_ud": "on"},
},
"fan_modes": {
"silent": {"wind_speed": 20},
"low": {"wind_speed": 40},
"medium": {"wind_speed": 60},
"high": {"wind_speed": 80},
"full": {"wind_speed": 100},
"auto": {"wind_speed": 102}
},
"target_temperature": ["temperature", "small_temperature"],
"current_temperature": "indoor_temperature",
"pre_mode": "mode",
"aux_heat": "ptc",
"min_temp": 17,
"max_temp": 30,
"temperature_unit": UnitOfTemperature.CELSIUS,
"precision": PRECISION_HALVES,
}
},
Platform.SWITCH: {
"dry": {
"device_class": SwitchDeviceClass.SWITCH,
},
"ptc": {
"device_class": SwitchDeviceClass.SWITCH,
"translation_key": "aux_heat",
}
},
Platform.SENSOR: {
"mode": {
"device_class": SensorDeviceClass.ENUM,
},
"indoor_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"outdoor_temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
}
}
}
}
}

View File

@@ -239,5 +239,66 @@ DEVICE_MAPPING = {
}
}
}
},
"7300073N": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": ["lightness"],
"entities": {
Platform.SWITCH: {
"power": {
"device_class": SwitchDeviceClass.SWITCH,
}
},
Platform.SENSOR: {
"total_working_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.TOTAL_INCREASING,
},
"wind_pressure": {
"device_class": SensorDeviceClass.PRESSURE,
"unit_of_measurement": UnitOfPressure.PA,
"state_class": SensorStateClass.MEASUREMENT
}
},
Platform.NUMBER: {
"lightness": {
"min": 10,
"max": 100,
"step": 5,
"command": {
"electronic_control_version": 2,
"type": "b6",
"b6_action": "setting",
"setting": "light",
"lightness": "{value}"
}
}
},
Platform.SELECT: {
"gear": {
"options": {
"off": {"gear": 0},
"low": {"gear": 1},
"medium": {"gear": 2},
"high": {"gear": 3},
"extreme": {"gear": 4},
}
},
"light": {
"options": {
"off": {"light": "off"},
"on": {"light": "on"}
},
"command": {
"electronic_control_version": 2,
"type": "b6",
"b6_action": "setting",
"setting": "light"
}
}
}
}
}
}

View File

@@ -384,21 +384,21 @@ DEVICE_MAPPING = {
},
"dehydration_speed": {
"options": {
"免脱水": {"dehydration_speed": "0"},
"400转": {"dehydration_speed": "400"},
"600转": {"dehydration_speed": "600"},
"800转": {"dehydration_speed": "800"},
"1000转": {"dehydration_speed": "1000"},
"1200转": {"dehydration_speed": "1200"},
"1400转": {"dehydration_speed": "1400"}
"免脱水": {"dehydration_speed": 0},
"400转": {"dehydration_speed": 400},
"600转": {"dehydration_speed": 600},
"800转": {"dehydration_speed": 800},
"1000转": {"dehydration_speed": 1000},
"1200转": {"dehydration_speed": 1200},
"1400转": {"dehydration_speed": 1400}
}
},
"soak_count": {
"options": {
"1次": {"soak_count": "1"},
"2次": {"soak_count": "2"},
"3次": {"soak_count": "3"},
"4次": {"soak_count": "4"}
"1次": {"soak_count": 1},
"2次": {"soak_count": 2},
"3次": {"soak_count": 3},
"4次": {"soak_count": 4}
}
},
"water_level": {
@@ -407,35 +407,145 @@ DEVICE_MAPPING = {
"L1": {"water_level": "low"},
"L2": {"water_level": "mid"},
"L3": {"water_level": "high"},
"L4": {"water_level": "4"}
"L4": {"water_level": 4}
}
},
"detergent": {
"options": {
"智能": {"detergent": "4"},
"关闭": {"detergent": "0"},
"L1": {"detergent": "1"},
"L2": {"detergent": "2"},
"L3": {"detergent": "3"},
"L4": {"detergent": "5"}
"智能": {"detergent": 4},
"关闭": {"detergent": 0},
"L1": {"detergent": 1},
"L2": {"detergent": 2},
"L3": {"detergent": 3},
"L4": {"detergent": 5}
}
},
"temperature": {
"options": {
"冷水": {"temperature": "0"},
"20℃": {"temperature": "20"},
"30℃": {"temperature": "30"},
"40℃": {"temperature": "40"},
"60℃": {"temperature": "60"},
"95℃": {"temperature": "95"}
"冷水": {"temperature": 0},
"20℃": {"temperature": 20},
"30℃": {"temperature": 30},
"40℃": {"temperature": 40},
"60℃": {"temperature": 60},
"95℃": {"temperature": 95}
}
},
"stains": {
"options": {
"关闭": {"stains": "0"},
"酱渍": {"stains": "83"},
"果渍": {"stains": "85"},
"妆渍": {"stains": "84"}
"关闭": {"stains": 0},
"酱渍": {"stains": 83},
"果渍": {"stains": 85},
"妆渍": {"stains": 84}
}
}
},
Platform.SENSOR: {
"running_status": {
"device_class": SensorDeviceClass.ENUM
},
"remain_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"progress": {
"device_class": SensorDeviceClass.BATTERY,
"unit_of_measurement": "%",
"state_class": SensorStateClass.MEASUREMENT
},
"error_code": {
"device_class": SensorDeviceClass.ENUM
},
"wash_time_value": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
},
"dehydration_time_value": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
}
}
}
},
"38124914": {
"rationale": ["off", "on"],
"queries": [{}],
"calculate": {
"get": [
{
"lvalue": "[remaining_time]",
"rvalue": "[remain_time]"
}
],
"set": {}
},
"entities": {
Platform.BINARY_SENSOR: {
"door_opened": {
"device_class": BinarySensorDeviceClass.OPENING,
},
"detergent_lack": {
"device_class": BinarySensorDeviceClass.PROBLEM,
}
},
Platform.SWITCH: {
"power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"control_status": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ["pause", "start"],
},
"lock": {
"device_class": SwitchDeviceClass.SWITCH,
"translation_key": "child_lock",
}
},
Platform.SELECT: {
"mode": {
"options": {
"normal": {"mode": "normal"},
"factory_test": {"mode": "factory_test"},
"service": {"mode": "service"},
"normal_continus": {"mode": "normal_continus"}
}
},
"soak_count": {
"options": {
"1次": {"soak_count": 1},
"2次": {"soak_count": 2},
"3次": {"soak_count": 3},
"4次": {"soak_count": 4}
}
},
"temperature": {
"options": {
"冷水": {"temperature": 0},
"20℃": {"temperature": 20},
"30℃": {"temperature": 30},
"40℃": {"temperature": 40},
"60℃": {"temperature": 60}
}
},
"program": {
"options": {
"baby_clothes": {"program": "baby_clothes"},
"cotton": {"program": "cotton"},
"enzyme": {"program": "enzyme"},
"fast_wash": {"program": "fast_wash"},
"fast_wash_30": {"program": "fast_wash_30"},
"mixed_wash": {"program": "mixed_wash"},
"remove_mite_wash": {"program": "remove_mite_wash"},
"shirt": {"program": "shirt"},
"single_dehytration": {"program": "single_dehytration"},
"sport_clothes": {"program": "sport_clothes"},
"ssp": {"program": "ssp"},
"steep": {"program": "steep"},
"underwear": {"program": "water_underwear"},
"kids": {"program": "kids"},
"cook_wash": {"program": "cook_wash"}
}
}
},

View File

@@ -128,5 +128,69 @@ DEVICE_MAPPING = {
},
}
}
},
"7600V1E7": {
"rationale": [0, 1],
"queries": [{}],
"centralized": [],
"entities": {
Platform.SWITCH: {
"airswitch": {
"device_class": SwitchDeviceClass.SWITCH,
},
"lock": {
"device_class": SwitchDeviceClass.SWITCH,
"translation_key": "child_lock"
}
},
Platform.NUMBER: {
"air_set_hour": {
"min": 1,
"max": 72,
"step": 1,
"unit_of_measurement": UnitOfTime.HOURS
}
},
Platform.SELECT: {
"work_status": {
"options": {
"power_off": {"work_status": "power_off" },
"power_on": {"work_status": "power_on" },
"cancel": {"work_status": "cancel" },
"pause": {"operator":"pause"},
"resume": {"operator":"start"},
}
},
"wash_mode": {
"options": {
"neutral_gear": {"work_status": "work", "mode": "neutral_gear"},
"auto_wash": {"work_status": "work", "mode": "auto_wash"},
"strong_wash": {"work_status": "work", "mode": "strong_wash"},
"standard_wash": {"work_status": "work", "mode": "standard_wash"},
"eco_wash": {"work_status":"work","mode":"eco_wash","additional":0,"wash_region":3},
"soft_wash": {"work_status": "work", "mode": "glass_wash"},
"fast_wash": {"work_status": "work", "mode": "fast_wash"},
"soak_wash": {"work_status": "work", "mode": "soak_wash"},
"self_clean": {"work_status": "work", "mode": "self_clean"},
"fruit_wash": {"work_status": "work", "mode": "fruit_wash"}
}
}
},
Platform.SENSOR: {
"bright": {
"device_class": SensorDeviceClass.ENUM
},
"temperature": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"left_time": {
"device_class": SensorDeviceClass.DURATION,
"unit_of_measurement": UnitOfTime.MINUTES,
"state_class": SensorStateClass.MEASUREMENT
}
}
}
}
}
}

View File

@@ -200,5 +200,103 @@ DEVICE_MAPPING = {
}
}
}
},
"571Z307F": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [],
"entities": {
Platform.NUMBER: {
"hosting_upper": {
"min": 10,
"max": 75,
"step": 1
},
"hosting_lower": {
"min": 10,
"max": 75,
"step": 1
}
},
Platform.SWITCH: {
"power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"buzzer": {
"device_class": SwitchDeviceClass.SWITCH,
"translation_key": "voice",
},
"lock": {
"device_class": SwitchDeviceClass.SWITCH,
"translation_key": "child_lock",
},
"waterions":{
"device_class": SwitchDeviceClass.SWITCH,
}
},
Platform.SELECT: {
"mode": {
"options": {
"manual": {"mode": "manual"},
"sleep": {"mode": "sleep"},
"auto": {"mode": "auto"},
"fast": {"mode": "fast"}
}
},
"bright": {
"options": {
"全亮": {"bright": 0},
"半亮": {"bright": 6},
"熄灭": {"bright": 7}
}
},
"gear": {
"options": {
"low": {"wind_speed": 1},
"medium": {"wind_speed": 2},
"high": {"wind_speed": 3}
}
},
"humidity": {
"options": {
"off": {"humidity": 0},
"40%": {"humidity": 40},
"50%": {"humidity": 50},
"60%": {"humidity": 60}
}
},
},
Platform.SENSOR: {
"deep_filter_percent": {
"unit_of_measurement": PERCENTAGE,
"state_class": SensorStateClass.MEASUREMENT
},
"temperature_feedback": {
"device_class": SensorDeviceClass.TEMPERATURE,
"unit_of_measurement": UnitOfTemperature.CELSIUS,
"state_class": SensorStateClass.MEASUREMENT
},
"humidify_feedback": {
"device_class": SensorDeviceClass.HUMIDITY,
"unit_of_measurement": "%",
"state_class": SensorStateClass.MEASUREMENT
},
"ash_tvoc":{
"unit_of_measurement": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
"state_class": SensorStateClass.MEASUREMENT,
"translation_key": "tvoc_value"
},
"pm25":{
"device_class": SensorDeviceClass.PM25,
"unit_of_measurement": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
"state_class": SensorStateClass.MEASUREMENT
},
"pm10":{
"device_class": SensorDeviceClass.PM10,
"unit_of_measurement": CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
"state_class": SensorStateClass.MEASUREMENT
}
}
}
}
}

View File

@@ -243,5 +243,54 @@ DEVICE_MAPPING = {
}
}
}
},
"202Z219V": {
"rationale": ["off", "on"],
"queries": [{}],
"centralized": [],
"entities": {
Platform.SWITCH: {
"power": {
"device_class": SwitchDeviceClass.SWITCH,
},
"bright_led": {
"device_class": SwitchDeviceClass.SWITCH,
"rationale": ["exit", "light"],
"translation_key": "light_mode"
}
},
Platform.SELECT: {
"humidity": {
"options": {
"40%": {"humidity": 40},
"45%": {"humidity": 45},
"50%": {"humidity": 50},
"55%": {"humidity": 55},
"60%": {"humidity": 60}
},
"command": {
"humidity_mode": "auto"
}
},
"wind_speed": {
"options": {
"low": {"wind_speed": "low"},
"middle": {"wind_speed": "middle"},
"high": {"wind_speed": "high"}
},
"command": {
"humidity_mode": "manual"
}
}
},
Platform.SENSOR: {
"cur_humidity": {
"device_class": SensorDeviceClass.HUMIDITY,
"unit_of_measurement": PERCENTAGE,
"state_class": SensorStateClass.MEASUREMENT
}
}
}
}
}
}

View File

@@ -84,29 +84,54 @@ class MideaLightEntity(MideaEntity, LightEntity):
self._brightness_key = key
break
# 检测色温配置类型:范围 [min_kelvin, max_kelvin] 或嵌套格式 {"color_temp": [min_kelvin, max_kelvin]}
# 检测色温配置类型:直接格式 或 嵌套格式
self._color_temp_is_range = False
self._color_temp_min = 2700 # 默认最小色温(暖白)
self._color_temp_max = 6500 # 默认最大色温(冷白)
self._color_temp_key = "color_temp" # 默认键名
self._color_temp_device_range = [1, 100] # 默认设备范围
if self._key_color_temp:
if isinstance(self._key_color_temp, list) and len(self._key_color_temp) == 2:
# 直接范围格式:[min_kelvin, max_kelvin]
if isinstance(self._key_color_temp[0], (int, float)) and isinstance(self._key_color_temp[1], (int, float)):
self._color_temp_is_range = True
self._color_temp_min = self._key_color_temp[0]
self._color_temp_max = self._key_color_temp[1]
elif isinstance(self._key_color_temp, dict):
# 嵌套格式:{"color_temp": [min_kelvin, max_kelvin]} 或其他键名
for key, value in self._key_color_temp.items():
if isinstance(value, list) and len(value) == 2:
if isinstance(value[0], (int, float)) and isinstance(value[1], (int, float)):
self._color_temp_is_range = True
self._color_temp_min = value[0]
self._color_temp_max = value[1]
self._color_temp_key = key
break
# 直接格式:{"kelvin_range": [min, max], "device_range": [min, max]}
if isinstance(self._key_color_temp, dict):
# 检查是否为直接格式包含kelvin_range和device_range
if "kelvin_range" in self._key_color_temp and "device_range" in self._key_color_temp:
kelvin_range = self._key_color_temp["kelvin_range"]
device_range = self._key_color_temp["device_range"]
if (
isinstance(kelvin_range, list)
and len(kelvin_range) == 2
and isinstance(device_range, list)
and len(device_range) == 2
):
self._color_temp_is_range = True
self._color_temp_min = kelvin_range[0]
self._color_temp_max = kelvin_range[1]
self._color_temp_device_range = device_range
# 直接格式没有外层key使用默认键名
self._color_temp_key = "color_temp"
# 嵌套格式:{"color_temperature": {"kelvin_range": [min, max], "device_range": [min, max]}}
else:
# 遍历字典中的每个键值对
for key, value in self._key_color_temp.items():
if isinstance(value, dict):
# 检测嵌套格式
if "kelvin_range" in value and "device_range" in value:
kelvin_range = value["kelvin_range"]
device_range = value["device_range"]
if (
isinstance(kelvin_range, list)
and len(kelvin_range) == 2
and isinstance(device_range, list)
and len(device_range) == 2
):
self._color_temp_is_range = True
self._color_temp_min = kelvin_range[0]
self._color_temp_max = kelvin_range[1]
self._color_temp_device_range = device_range
self._color_temp_key = key
break
@property
def supported_features(self):
@@ -165,11 +190,9 @@ class MideaLightEntity(MideaEntity, LightEntity):
if brightness_value is not None:
brightness_value = int(brightness_value)
if brightness_value is not None:
# 如果配置是[0, 255]但实际设备范围是1-100需要特殊处理
# 配置是[0, 255]直接使用
if self._brightness_min == 0 and self._brightness_max == 255:
# 特殊处理设备1-100范围映射到HA的0-255范围
ha_brightness = round(brightness_value * 2.55) # 1-100 -> 0-255
return max(1, min(255, ha_brightness))
return max(1, min(255, brightness_value))
else:
# 正常范围映射
device_range = self._brightness_max - self._brightness_min
@@ -183,18 +206,26 @@ class MideaLightEntity(MideaEntity, LightEntity):
"""返回当前色温值(开尔文)"""
if not self._color_temp_is_range:
return None
# 从设备属性读取色温值1-100范围
# 从设备属性读取色温值
color_temp_value = self._get_nested_value(self._color_temp_key)
if color_temp_value is not None:
try:
device_color_temp = int(color_temp_value)
# 将设备的1-100值转换为开尔文值
device_value = int(color_temp_value)
device_min, device_max = self._color_temp_device_range
# 将设备值转换为开尔文值
kelvin_range = self._color_temp_max - self._color_temp_min
if kelvin_range > 0:
# 将1-100范围映射开尔文范围
ha_color_temp = self._color_temp_min + device_color_temp * kelvin_range / 100
return round(ha_color_temp)
# 将设备值映射开尔文范围
device_range = device_max - device_min
if device_range > 0:
# 设备值 -> 开尔文
normalized = (device_value - device_min) / device_range
ha_color_temp = self._color_temp_min + normalized * kelvin_range
return round(ha_color_temp)
else:
return self._color_temp_min
else:
return self._color_temp_min
except (ValueError, TypeError):
@@ -244,11 +275,11 @@ class MideaLightEntity(MideaEntity, LightEntity):
if target_brightness is not None and self._key_brightness and self._brightness_is_range:
# 范围模式将Home Assistant的0-255映射到设备范围
# 如果配置是[0, 255]但实际设备范围是1-100需要特殊处理
target_brightness = max(0, min(255, target_brightness))
# 配置是[0, 255]直接使用
if self._brightness_min == 0 and self._brightness_max == 255:
# 特殊处理:配置[0,255]但实际设备范围是1-100
device_brightness = round(target_brightness / 2.55) # 0-255 -> 0-100
device_brightness = max(1, min(100, device_brightness)) # 确保在1-100范围内
device_brightness = target_brightness
else:
# 正常范围映射
device_range = self._brightness_max - self._brightness_min
@@ -263,18 +294,23 @@ class MideaLightEntity(MideaEntity, LightEntity):
if color_temp_kelvin is not None and self._color_temp_is_range:
# 确保色温值在配置的范围内
ha_color_temp = max(self._color_temp_min, min(self._color_temp_max, color_temp_kelvin))
# 将开尔文值转换为设备范围1-100
device_min, device_max = self._color_temp_device_range
kelvin_range = self._color_temp_max - self._color_temp_min
if kelvin_range > 0:
# 将开尔文值映射到1-100范围
device_color_temp = round((ha_color_temp - self._color_temp_min) * 100 / kelvin_range)
device_color_temp = max(0, min(100, device_color_temp))
device_range = device_max - device_min
if device_range > 0:
normalized = (ha_color_temp - self._color_temp_min) / kelvin_range
device_value = round(device_min + normalized * device_range)
device_value = max(device_min, min(device_max, device_value))
else:
device_value = device_min
else:
device_color_temp = 50 # 默认中间值
new_status[self._color_temp_key] = str(device_color_temp)
device_value = device_min
new_status[self._color_temp_key] = str(device_value)
await self._async_set_status_on_off(self._key_power, True)
if new_status:
await self.async_set_attributes(new_status)

View File

@@ -364,6 +364,16 @@
"silent": "Silent",
"full": "Full"
}
},
"swing_mode": {
"state": {
"horizontal_upper_only": "Horizontal Swing Upper",
"horizontal_under_only": "Horizontal Swing Under",
"horizontal_upper_under": "Horizontal Swing Upper And Under",
"horizontal_upper_vertical": "Horizontal Swing Upper And Vertical",
"horizontal_under_vertical": "Horizontal Swing Under And Vertical",
"vertical_only": "Vertical Swing"
}
}
}
},
@@ -880,6 +890,7 @@
"standard_wash": "standard wash",
"eco_wash": "eco wash",
"glass_wash": "glass wash",
"soft_wash": "soft wash",
"hour_wash": "hour wash",
"fast_wash": "fast wash",
"soak_wash": "soak wash",
@@ -2203,6 +2214,12 @@
}
},
"number": {
"air_set_hour": {
"name": "Drying Storage Set Time"
},
"delay_light_off": {
"name": "Delay Light Off"
},
"hosting_upper": {
"name": "PM2.5 Upper(Auto Purification)"
},

View File

@@ -384,6 +384,16 @@
"silent": "静音",
"full": "强劲"
}
},
"swing_mode": {
"state": {
"horizontal_upper_only": "上左右风",
"horizontal_under_only": "下左右风",
"horizontal_upper_under": "上+下左右风",
"horizontal_upper_vertical": "上左右风+上下摆风",
"horizontal_under_vertical": "下左右风+上下摆风",
"vertical_only": "上下摆风"
}
}
}
},
@@ -546,7 +556,11 @@
"name": "降噪设置"
},
"humidity": {
"name": "设定湿度"
"name": "设定湿度",
"state": {
"off": "关闭",
"auto": "自动"
}
},
"b3_function_control": {
"name": "消毒柜控制"
@@ -935,7 +949,7 @@
"water_ssp": "水韵超净洗",
"standard": "标准洗",
"green_wool": "绿色羊毛",
"cook_wash": "厨师服洗",
"cook_wash": "高温洗",
"fresh_remove_wrinkle": "清新除皱",
"steam_sterilize_wash": "蒸汽消毒洗",
"aromatherapy": "香薰洗",
@@ -1063,6 +1077,7 @@
"standard_wash": "标准洗",
"eco_wash": "节能洗",
"glass_wash": "玻璃洗",
"soft_wash": "轻柔洗",
"hour_wash": "小时洗",
"fast_wash": "快速洗",
"soak_wash": "预冲洗",
@@ -2493,10 +2508,28 @@
},
"light": {
"light": {
"name": "电灯"
"name": "电灯",
"state_attributes": {
"effect": {
"state": {
"night": "夜灯",
"read": "阅读",
"mild": "柔和",
"life": "生活",
"film": "影院",
"manual": "自定义"
}
}
}
}
},
"number": {
"air_set_hour": {
"name": "烘干存储设置时间"
},
"delay_light_off": {
"name": "延时关灯"
},
"hosting_upper": {
"name": "PM2.5上阈值(自动净化)"
},