Skip to content

Commit

Permalink
Support PM2.5 for AC
Browse files Browse the repository at this point in the history
  • Loading branch information
sugoi-wada committed Nov 3, 2021
1 parent d865b1d commit a872f02
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
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

0 comments on commit a872f02

Please sign in to comment.