From a872f0231d5702f05847fb84b620272f39e6ffdc Mon Sep 17 00:00:00 2001 From: Hikaru Wada Date: Wed, 3 Nov 2021 12:37:08 +0900 Subject: [PATCH 1/2] Support PM2.5 for AC --- .../panasonic_smart_app/const.py | 1 + .../panasonic_smart_app/sensor.py | 35 ++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/custom_components/panasonic_smart_app/const.py b/custom_components/panasonic_smart_app/const.py index 3457c07..1dcb8d6 100644 --- a/custom_components/panasonic_smart_app/const.py +++ b/custom_components/panasonic_smart_app/const.py @@ -56,6 +56,7 @@ "0x11", # AC fan position (vertical) "0x19", # AC motion detection "0x1F", # AC indicator light + "0x37", # AC PM2.5 ], DEVICE_TYPE_DEHUMIDIFIER: [ "0x00", # Dehumidifier power status diff --git a/custom_components/panasonic_smart_app/sensor.py b/custom_components/panasonic_smart_app/sensor.py index f72fed2..4e33417 100644 --- a/custom_components/panasonic_smart_app/sensor.py +++ b/custom_components/panasonic_smart_app/sensor.py @@ -1,3 +1,4 @@ +from abc import ABC, abstractmethod from datetime import datetime, timedelta import logging from homeassistant.components.sensor import SensorEntity @@ -63,7 +64,7 @@ async def async_setup_entry(hass, entry, async_add_entities) -> bool: ) ) sensors.append( - PanasonicPM25Sensor( + PanasonicDehumidifierPM25Sensor( coordinator, index, client, @@ -80,6 +81,14 @@ async def async_setup_entry(hass, entry, async_add_entities) -> bool: device, ) ) + sensors.append( + PanasonicACPM25Sensor( + coordinator, + index, + client, + device, + ) + ) async_add_entities(sensors, True) @@ -117,8 +126,13 @@ def unit_of_measurement(self) -> str: return PERCENTAGE -class PanasonicPM25Sensor(PanasonicBaseEntity, SensorEntity): - """ Panasonic dehumidifer PM2.5 sensor """ +class PanasonicPM25Sensor(PanasonicBaseEntity, SensorEntity, ABC): + + @property + @abstractmethod + def command_type(self) -> str: + """Command type for PM2.5 sensor.""" + ... @property def label(self) -> str: @@ -135,7 +149,7 @@ def device_class(self) -> str: @property def state(self) -> int: status = self.coordinator.data[self.index]["status"] - _pm25 = float(status.get("0x53", -1)) + _pm25 = float(status.get(self.command_type, -1)) _LOGGER.debug(f"[{self.label}] state: {_pm25}") return _pm25 if _pm25 >= 0 else STATE_UNAVAILABLE @@ -147,6 +161,19 @@ def state_class(self) -> str: def unit_of_measurement(self) -> str: return CONCENTRATION_MICROGRAMS_PER_CUBIC_METER +class PanasonicDehumidifierPM25Sensor(PanasonicPM25Sensor): + """ Panasonic Dehumidifier PM2.5 sensor """ + + @property + def command_type(self) -> str: + return "0x53" + +class PanasonicACPM25Sensor(PanasonicPM25Sensor): + """ Panasonic AC PM2.5 sensor """ + + @property + def command_type(self) -> str: + return "0x37" class PanasonicOutdoorTemperatureSensor(PanasonicBaseEntity, SensorEntity): """ Panasonic AC outdoor temperature sensor """ From 4fe2816f20c5bb2ffd8bb12760efb424a471cfdc Mon Sep 17 00:00:00 2001 From: osk2 Date: Sat, 6 Nov 2021 15:05:20 +0800 Subject: [PATCH 2/2] Update documentation --- README-zh.md | 1 + README.md | 1 + info.md | 42 +++++++++++++++++++++++++----------------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/README-zh.md b/README-zh.md index de8e570..dd4f849 100644 --- a/README-zh.md +++ b/README-zh.md @@ -71,6 +71,7 @@ _完整的實體清單請見 [可用的實體](#可用的實體)_ | | number | 定時開機\* | | | number | 定時關機 | | | sensor | 室外溫度偵測器 | +| | sensor | PM2.5 偵測器 | | | switch | nanoe 開關\* | | | switch | ECONAVI 開關\* | | | switch | 操控聲音開關\* | diff --git a/README.md b/README.md index 29c3eee..2b30167 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ Feel free to report working device by opening an [issue](https://github.com/osk2 | | number | On timer\* | | | number | Off timer | | | sensor | Outdoor temperature sensor | +| | sensor | PM2.5 sensor | | | switch | nanoe switch\* | | | switch | ECONAVI swtich\* | | | switch | Buzzer switch\* | diff --git a/info.md b/info.md index b8d84a3..bcc4a94 100644 --- a/info.md +++ b/info.md @@ -45,26 +45,34 @@ Feel free to report working device by opening an [issue](https://github.com/osk2 ### Available Entities -| Device Type | Entity Type | Note | -| ------------ | ------------- | --------------------------- | -| AC | climate | | -| | number | On timer\* | -| | number | Off timer | -| | sensor | Outdoor temperature sensor | -| | switch | nanoe switch\* | -| | switch | ECONAVI swtich\* | -| | switch | Buzzer switch\* | -| | switch | Turbo mode switch\* | -| Dehumidifier | humidifier | | -| | number | On timer\* | -| | number | Off timer | -| | select | Fan mode | -| | sensor | Environment humidity sensor | -| | sensor | PM2.5 sensor | -| | binary_sensor | Water tank status sensor | +| Device Type | Entity Type | Note | +| ------------ | ------------- | ------------------------------ | +| AC | climate | | +| | number | On timer\* | +| | number | Off timer | +| | sensor | Outdoor temperature sensor | +| | sensor | PM2.5 sensor | +| | switch | nanoe switch\* | +| | switch | ECONAVI swtich\* | +| | switch | Buzzer switch\* | +| | switch | Turbo mode switch\* | +| | switch | Self-clean mode switch\* | +| | switch | Anti-mold mode switch\* | +| | switch | Sleep mode switch\* | +| | select | Motion detection mode select\* | +| | select | Indicator light select\* | +| Dehumidifier | humidifier | | +| | number | On timer\* | +| | number | Off timer | +| | select | Fan mode\* | +| | sensor | Environment humidity sensor | +| | sensor | PM2.5 sensor | +| | binary_sensor | Water tank status sensor | \*Only available if feature is supported. +Note: Make sure latest Home Assistant is installed or some entities might not available. + For missing entities, open an [issue](https://github.com/osk2/panasonic_smart_app/issues) or submit a PR 💪 ### Enable Logs