Skip to content

Commit

Permalink
Merge pull request #41 from sugoi-wada/pm25
Browse files Browse the repository at this point in the history
Support PM2.5 for AC
  • Loading branch information
osk2 authored Nov 6, 2021
2 parents d865b1d + 4fe2816 commit a2927e4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 21 deletions.
1 change: 1 addition & 0 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ _完整的實體清單請見 [可用的實體](#可用的實體)_
| | number | 定時開機\* |
| | number | 定時關機 |
| | sensor | 室外溫度偵測器 |
| | sensor | PM2.5 偵測器 |
| | switch | nanoe 開關\* |
| | switch | ECONAVI 開關\* |
| | switch | 操控聲音開關\* |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\* |
Expand Down
1 change: 1 addition & 0 deletions custom_components/panasonic_smart_app/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 31 additions & 4 deletions custom_components/panasonic_smart_app/sensor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from abc import ABC, abstractmethod
from datetime import datetime, timedelta
import logging
from homeassistant.components.sensor import SensorEntity
Expand Down Expand Up @@ -63,7 +64,7 @@ async def async_setup_entry(hass, entry, async_add_entities) -> bool:
)
)
sensors.append(
PanasonicPM25Sensor(
PanasonicDehumidifierPM25Sensor(
coordinator,
index,
client,
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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 """
Expand Down
42 changes: 25 additions & 17 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a2927e4

Please sign in to comment.