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

Refactored units and icons for the Dyson sensors #14550

Merged
merged 7 commits into from Sep 21, 2018

Conversation

glpatcern
Copy link
Contributor

Description:

This PR bears a number of improvements for the Dyson sensors, to bring them to the HA standard:

  • a default icon is assigned to all sensors
  • sensor name initials are capitalized
  • the unit of measurement for the levels/indexes is empty, This may be questionable, but from a measurement point of view, quality indexes are pure numbers.
  • the "air quality" sensor was renamed AQI for Air Quality Index, following Dyson's mobile app

The latter change is a breaking change.

Related issue (if applicable): N/A

Pull request in home-assistant.github.io with documentation (if applicable): N/A (though the sensors' names could be documented)

Example entry for configuration.yaml (if applicable): N/A

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@@ -14,12 +14,20 @@
DEPENDENCIES = ['dyson']

SENSOR_UNITS = {
'air_quality': 'level',
'dust': 'level',
'air_quality': '',
Copy link
Member

Choose a reason for hiding this comment

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

I assume None is preferred instead of an empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well spotted, I see other sensors having None indeed as unit. Fixed by the next commit.

@fabaff
Copy link
Member

fabaff commented May 29, 2018

@CharlesBlonde, could you please take a look at this? Thanks

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Use super to call the parent class init method.

@@ -43,12 +51,13 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class DysonSensor(Entity):
"""Representation of Dyson sensor."""

def __init__(self, hass, device):
def __init__(self, hass, device, sensor_type):
Copy link
Member

Choose a reason for hiding this comment

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

Don't pass in hass. It will be set on the entity when it has been added to home assistant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good to know. It's true that most of the sensors do not have hass in the __init__() signature (but a good fraction of them still has it...).

I'm happy to do the change, but just to note that both suggestions refer to the original code, not to this PR, and my attempt was to minimize the change.

Copy link
Member

Choose a reason for hiding this comment

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

Since you're changing these lines, please clean it up.


class DysonFilterLifeSensor(DysonSensor):
"""Representation of Dyson filter life sensor (in hours)."""

def __init__(self, hass, device):
"""Create a new Dyson filter life sensor."""
DysonSensor.__init__(self, hass, device)
self._name = "{} filter life".format(self._device.name)
DysonSensor.__init__(self, hass, device, 'filter_life')
Copy link
Member

Choose a reason for hiding this comment

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

super().__init__(device, 'filter_life')

@CharlesBlonde
Copy link
Contributor

CharlesBlonde commented May 31, 2018 via email

@glpatcern
Copy link
Contributor Author

Hi @CharlesBlonde, whenever you can please have a look at the latest version, which includes an overall refactoring. It works for my setup.

@glpatcern
Copy link
Contributor Author

For info, the CI test failed because in the test environment it seems that hass is not set on the entity:

self = <Entity Device_name Filter Life: None>, force_refresh = False
    def schedule_update_ha_state(self, force_refresh=False):
        """Schedule an update ha state change task.
    
            That avoid executor dead looks.
            """
>       self.hass.add_job(self.async_update_ha_state(force_refresh))
E       AttributeError: 'NoneType' object has no attribute 'add_job'

Whereas in the real environment that works. @MartinHjelmare, what would be your suggestion to fix the tests?

@MartinHjelmare
Copy link
Member

Simple way is to set hass attribute on each entity before calling on_message. You have access to hass as self.hass in the tests. The longer route would be to actually add the devices to home assistant during platform setup before calling on_message.

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good!

@MartinHjelmare
Copy link
Member

I'll wait for @CharlesBlonde or @fabaff to give the go ahead.

@MartinHjelmare
Copy link
Member

@CharlesBlonde or @fabaff any further input? Otherwise I'll merge.

@glpatcern
Copy link
Contributor Author

glpatcern commented Aug 12, 2018

As a side note, I didn't further push for this because lately the Dyson integration is broken for me for about a month now. Nothing related to Home Assistant, but rather the underlying libpurecoollink is unable to logon, as if Dyson upgraded their logon logic.

Did not have time to debug it, but maybe @CharlesBlonde knows more and/or experienced the same? If so, that's obviously out of scope for this PR and we should follow it up with libpurecoollink.

@ghost ghost assigned balloob Sep 21, 2018
@balloob balloob merged commit 2131717 into home-assistant:dev Sep 21, 2018
@ghost ghost removed the almost-done label Sep 21, 2018
@balloob balloob mentioned this pull request Sep 28, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants