Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PM10, PM2, PM1 sensors to AC-device #613

Merged
merged 10 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions custom_components/smartthinq_sensors/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,27 @@ class ThinQSensorEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=PERCENTAGE,
),
ThinQSensorEntityDescription(
key=AirConditionerFeatures.PM1,
name="PM1",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.PM1,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
),
ThinQSensorEntityDescription(
key=AirConditionerFeatures.PM10,
name="PM10",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.PM10,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
),
ThinQSensorEntityDescription(
key=AirConditionerFeatures.PM25,
name="PM2.5",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.PM25,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
),
ThinQSensorEntityDescription(
key=AirConditionerFeatures.FILTER_MAIN_LIFE,
name="Filter Remaining Life",
Expand Down
3 changes: 3 additions & 0 deletions custom_components/smartthinq_sensors/wideq/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class AirConditionerFeatures(StrEnum):
MODE_AIRCLEAN = "mode_airclean"
MODE_AWHP_SILENT = "mode_awhp_silent"
MODE_JET = "mode_jet"
PM1 = "pm1"
PM10 = "pm10"
PM25 = "pm25"
RESERVATION_SLEEP_TIME = "reservation_sleep_time"
ROOM_TEMP = "room_temperature"
WATER_IN_TEMP = "water_in_temperature"
Expand Down
40 changes: 40 additions & 0 deletions custom_components/smartthinq_sensors/wideq/devices/ac.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

AWHP_MODEL_TYPE = ["AWHP", "SAC_AWHP"]

SUPPORT_AIR_POLUTION = ["SupportAirPolution", "support.airPolution"]
SUPPORT_OPERATION_MODE = ["SupportOpMode", "support.airState.opMode"]
SUPPORT_WIND_STRENGTH = ["SupportWindStrength", "support.airState.windStrength"]
SUPPORT_DUCT_ZONE = ["SupportDuctZoneType", "support.airState.ductZone.type"]
Expand Down Expand Up @@ -64,6 +65,9 @@
STATE_MODE_AIRCLEAN = ["AirClean", "airState.wMode.airClean"]
STATE_MODE_JET = ["Jet", "airState.wMode.jet"]
STATE_LIGHTING_DISPLAY = ["DisplayControl", "airState.lightingState.displayControl"]
STATE_PM1 = ["SensorPM1", "airState.quality.PM1"]
STATE_PM10 = ["SensorPM10", "airState.quality.PM10"]
STATE_PM25 = ["SensorPM2", "airState.quality.PM2"]
skinkie marked this conversation as resolved.
Show resolved Hide resolved
STATE_RESERVATION_SLEEP_TIME = ["SleepTime", "airState.reservation.sleepTime"]

FILTER_TYPES = [
Expand Down Expand Up @@ -1247,6 +1251,39 @@ def filters_life(self):

return result

@property
def pm1(self):
"""Return Air PM1 value."""
support_key = self._get_state_key(SUPPORT_AIR_POLUTION)
if self._device.model_info.enum_value(support_key, "@PM1_0_SUPPORT") is None:
return None
Copy link
Owner

@ollo69 ollo69 Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest here to create a new function at device level, eg. is_pm_supported (similar, for example to is_mode_airclean_supported), to avoid to scan model_info every status refresh.

You could start creating a new constant:

SUPPORT_PM = [SUPPORT_AIR_POLUTION, ["@PM1_0_SUPPORT", "@PM10_SUPPORT", "@PM2_5_SUPPORT"]]

In the new function you should loop the second array and createa new boolean array (and store this in a new device attribute) that represent supported PM type.

Then here you can just call the device method that will scan model_info only on the first call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commited in 7cb81de.

Do you have any suggestion how to debug this component outside homeassistant?

Copy link
Owner

@ollo69 ollo69 Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Install Docker Desktop and Visual studio code
  • Open the project with Visual studio code
  • When the project is open, select the option clone in a new volume
  • A new environment will be created, and you can run a copy of HA with integration for test (command palette -> run task -> run home assistant core).

Do you want that I wait for your test result before merging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I test this code now by every time copying it to my 'live' HA. But there was an issue yesterday where I made a mistake and only saw in the evening what the issue actually was. I wondered if there was an option just to run this part of the code, for example in pycharm, so that debugging options are available.

key = self._get_state_key(STATE_PM1)
if (value := self.lookup_range(key)) is None:
return None
return self._update_feature(AirConditionerFeatures.PM1, value, False)

@property
def pm10(self):
"""Return Air PM10 value."""
support_key = self._get_state_key(SUPPORT_AIR_POLUTION)
if self._device.model_info.enum_value(support_key, "@PM10_SUPPORT") is None:
return None
key = self._get_state_key(STATE_PM10)
if (value := self.lookup_range(key)) is None:
return None
return self._update_feature(AirConditionerFeatures.PM10, value, False)

@property
def pm25(self):
"""Return Air PM2.5 value."""
support_key = self._get_state_key(SUPPORT_AIR_POLUTION)
if self._device.model_info.enum_value(support_key, "@PM2_5_SUPPORT") is None:
return None
key = self._get_state_key(STATE_PM25)
if (value := self.lookup_range(key)) is None:
return None
return self._update_feature(AirConditionerFeatures.PM25, value, False)

@property
def water_in_current_temp(self):
"""Return AWHP in water current temperature."""
Expand Down Expand Up @@ -1343,6 +1380,9 @@ def _update_features(self):
self.energy_current,
self.filters_life,
self.humidity,
self.pm10,
self.pm25,
self.pm1,
self.mode_airclean,
self.mode_jet,
self.lighting_display,
Expand Down