From 7e2f10be0f1f80e50ad0b3d88efc3b722d7e2a2a Mon Sep 17 00:00:00 2001 From: Maple Gao Date: Sun, 28 Apr 2024 18:10:28 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[2024-04-28]=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=B0=E7=89=B9=E6=80=A7:=20=E5=9C=A8=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=BC=A0=E6=84=9F=E5=99=A8=E4=B8=AD=E5=A2=9E=E5=8A=A0=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=BC=A0=E6=84=9F=E5=99=A8=E6=9B=B4=E6=96=B0=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=97=B6=EF=BC=8Cws=20=E5=AE=9E=E6=97=B6=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=9A=84=E6=9B=B4=E6=96=B0=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- custom_components/lifesmart/sensor.py | 36 +++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/custom_components/lifesmart/sensor.py b/custom_components/lifesmart/sensor.py index fba2866..6ec59ab 100644 --- a/custom_components/lifesmart/sensor.py +++ b/custom_components/lifesmart/sensor.py @@ -32,9 +32,6 @@ SMART_PLUG_TYPES, ) -# DOMAIN = "sensor" -# ENTITY_ID_FORMAT = DOMAIN + ".{}" - _LOGGER = logging.getLogger(__name__) @@ -117,7 +114,6 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class LifeSmartSensor(SensorEntity): """Representation of a LifeSmartSensor.""" - # def __init__(self, dev, idx, val, param) -> None: def __init__( self, device, raw_device_data, sub_device_key, sub_device_data, client ) -> None: @@ -237,5 +233,35 @@ async def async_added_to_hass(self) -> None: async def _update_value(self, data) -> None: if data is not None: - self._state = data["v"] + if self.device_type in GAS_SENSOR_TYPES: + self._state = data["val"] + elif self.device_type in SMART_PLUG_TYPES and self.sub_device_key == "P2": + self._state = data["v"] + elif self.device_type in SMART_PLUG_TYPES and self.sub_device_key == "P3": + self._state = data["v"] + else: + self._state = data["v"] + + if self.sub_device_key in ["T", "P1"]: + self._device_class = SensorDeviceClass.TEMPERATURE + self._unit = UnitOfTemperature.CELSIUS + elif self.sub_device_key in ["H", "P2"]: + self._device_class = SensorDeviceClass.HUMIDITY + self._unit = PERCENTAGE + elif self.sub_device_key == "Z": + self._device_class = SensorDeviceClass.ILLUMINANCE + self._unit = LIGHT_LUX + elif self.sub_device_key == "V": + self._device_class = SensorDeviceClass.BATTERY + self._unit = PERCENTAGE + elif self.sub_device_key == "P3": + self._device_class = "None" + self._unit = CONCENTRATION_PARTS_PER_MILLION + elif self.sub_device_key == "P4": + self._device_class = "None" + self._unit = CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER + elif self.sub_device_key == "BAT": + self._device_class = SensorDeviceClass.BATTERY + self._unit = PERCENTAGE + self.schedule_update_ha_state()