-
Notifications
You must be signed in to change notification settings - Fork 159
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR.
Please attach your integration diagnostic so that I can test this feature.
@ollo69 where can I find the integration diagnostic? |
I think what would be nice is if #614 is added, to make the sensor availability dependent on ('airMon' or not 'poweroff'), so there wouldn't be a false sense of security based on the minimum value. |
It is better to proceed by step. When this PR is completed and merged you can rebase #614 to provide additional features. |
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@property | ||
def is_pm10_supported(self): | ||
"""Return if PM sensors are supported.""" | ||
if self._is_pm_supported is None: | ||
self._is_pm_supported = self._is_mode_supported(SUPPORT_PM) | ||
return self._is_pm_supported[0] | ||
|
||
@property | ||
def is_pm25_supported(self): | ||
"""Return if PM sensors are supported.""" | ||
if self._is_pm_supported is None: | ||
self._is_pm_supported = self._is_mode_supported(SUPPORT_PM) | ||
return self._is_pm_supported[2] | ||
|
||
@property | ||
def is_pm1_supported(self): | ||
"""Return if PM sensors are supported.""" | ||
if self._is_pm_supported is None: | ||
self._is_pm_supported = self._is_mode_supported(SUPPORT_PM) | ||
return self._is_pm_supported[1] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that I like to have 3 different properties, because I'm planning to replace cache attributes with cached_property and I couldn't use in this case.
Apart this I like this approach, I'll think about this later.
Maybe should be better to order the array in different way (PM1, PM25 and PM10)? Or you use this order for a specific reason (I'm not a PM expert)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because from a human readability standpoint I liked:
1 = PM1
2 = PM2
0 = PM10 ;-)
I initially modelled this as a dictionary, with a key lookup, but for some reason, I could not get def is_pm_supported(self, key):
working.
Please fix linting. If you use dev environment as explained above, black formatting is applied by Visual Studio on save. |
For this project I am using vim. Any thing I can run from the commandline? |
Vim, the programming environment for people who don't have to ask 😉. |
Oh you actually now ran the tests. To be honest I have never heard about "black" before. Isn't |
@ollo69 model_info.py is changed by black too. |
Probably because you are not using right parameters for formatting |
I ran |
Probably you are using wrong black version. Check |
Indeed. 20 vs 23. |
This is my first copy-paste code for this project. I have not ran the code, as I first have to figure out how to do so in the HACS situation.
Fix #606