mirror of
https://github.com/sususweet/midea-meiju-codec.git
synced 2025-12-17 09:55:51 +00:00
feat: external humidity sensor support. by @jesusya
This commit is contained in:
@@ -52,7 +52,12 @@ DEVICE_MAPPING = {
|
|||||||
"manual": {"humidity_mode": "manual"},
|
"manual": {"humidity_mode": "manual"},
|
||||||
"moist_skin": {"humidity_mode": "moist_skin"},
|
"moist_skin": {"humidity_mode": "moist_skin"},
|
||||||
"sleep": {"humidity_mode": "sleep"}
|
"sleep": {"humidity_mode": "sleep"}
|
||||||
}
|
},
|
||||||
|
# "external_humidity_sensor_map": {
|
||||||
|
# # "202Z3XXX": "sensor.temperature_humidity_sensor_6510_humidity",
|
||||||
|
# # "设备2-sn8": "sensor.master_bedroom_humidity",
|
||||||
|
# # "设备3-sn8": "sensor.studyroom_humidity"
|
||||||
|
# }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Platform.SELECT: {
|
Platform.SELECT: {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
from .core.logger import MideaLogger
|
||||||
from .midea_entity import MideaEntity
|
from .midea_entity import MideaEntity
|
||||||
from . import load_device_config
|
from . import load_device_config
|
||||||
|
|
||||||
@@ -64,6 +65,13 @@ class MideaHumidifierEntity(MideaEntity, HumidifierEntity):
|
|||||||
self._attr_supported_features = HumidifierEntityFeature.MODES
|
self._attr_supported_features = HumidifierEntityFeature.MODES
|
||||||
self._attr_available_modes = list(self._config.get("modes").keys())
|
self._attr_available_modes = list(self._config.get("modes").keys())
|
||||||
|
|
||||||
|
# 新增:外部湿度传感器支持
|
||||||
|
# 设备当前使用加湿器内置湿度传感器。如需外接更高精度传感器,可在midea_auto_cloud/device_mapping设备对应文件中编辑 'external_humidity_sensor_map' 部分进行配置
|
||||||
|
external_map = self._config.get("external_humidity_sensor_map", {})
|
||||||
|
self._has_external_sensor = self._sn8 in external_map
|
||||||
|
if self._has_external_sensor:
|
||||||
|
self._external_sensor_id = external_map[self._sn8]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the device class."""
|
"""Return the device class."""
|
||||||
@@ -91,6 +99,21 @@ class MideaHumidifierEntity(MideaEntity, HumidifierEntity):
|
|||||||
@property
|
@property
|
||||||
def current_humidity(self):
|
def current_humidity(self):
|
||||||
"""Return the current humidity."""
|
"""Return the current humidity."""
|
||||||
|
# 支持外部湿度传感器 jesusya
|
||||||
|
if self._has_external_sensor:
|
||||||
|
state = self.hass.states.get(self._external_sensor_id)
|
||||||
|
if state and state.state not in (None, "unknown", "unavailable"):
|
||||||
|
try:
|
||||||
|
new_humidity = round(float(state.state))
|
||||||
|
self._current_humidity = new_humidity
|
||||||
|
MideaLogger.debug(f"{self.entity_id} using external sensor humidity from {self._external_sensor_id}: {self._current_humidity}")
|
||||||
|
return self._current_humidity
|
||||||
|
except (ValueError, TypeError, AttributeError) as e:
|
||||||
|
MideaLogger.warning(f"{self.entity_id} failed to parse external sensor state from {self._external_sensor_id}: {e}")
|
||||||
|
else:
|
||||||
|
MideaLogger.warning(f"{self.entity_id} external sensor {self._external_sensor_id} unavailable")
|
||||||
|
|
||||||
|
# 回退到内部传感器或直接使用内部传感器
|
||||||
current_humidity_key = self._config.get("current_humidity")
|
current_humidity_key = self._config.get("current_humidity")
|
||||||
if current_humidity_key:
|
if current_humidity_key:
|
||||||
return self.device_attributes.get(current_humidity_key, 0)
|
return self.device_attributes.get(current_humidity_key, 0)
|
||||||
@@ -131,7 +154,7 @@ class MideaHumidifierEntity(MideaEntity, HumidifierEntity):
|
|||||||
power_key = self._config.get("power")
|
power_key = self._config.get("power")
|
||||||
if power_key:
|
if power_key:
|
||||||
await self._device.set_attribute(power_key, self._rationale[int(False)])
|
await self._device.set_attribute(power_key, self._rationale[int(False)])
|
||||||
await self._device.set_attribute(power_key, self._rationale[int(False)])
|
await self._device.set_attribute(power_key, self._rationale[int(False)]) #避免美的加湿器,挂机启动风干湿帘,噪音过大
|
||||||
|
|
||||||
async def async_set_humidity(self, humidity: int):
|
async def async_set_humidity(self, humidity: int):
|
||||||
"""Set the target humidity."""
|
"""Set the target humidity."""
|
||||||
|
|||||||
Reference in New Issue
Block a user