Skip to content

Add Sensibo climate platform#7379

Merged
balloob merged 6 commits into
home-assistant:devfrom
andrey-git:sensibo
May 3, 2017
Merged

Add Sensibo climate platform#7379
balloob merged 6 commits into
home-assistant:devfrom
andrey-git:sensibo

Conversation

@andrey-git
Copy link
Copy Markdown
Contributor

@andrey-git andrey-git commented Apr 30, 2017

Description:

Add Sensibo a/c remote as a climate platform.

To make it work correctly also added a new target_temp_step attribute to climate (defaults to None) so that UI can know the temperature granularity the platform supports.
home-assistant/frontend#270 is the UI counterpart.

Documentation is in progress...

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2546

Example entry for configuration.yaml (if applicable):

climate:
  - platform: sensibo
  - api_key: deadbeafdeadbeaf
  - id: unitid

Checklist:

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

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

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable ([example][ex-requir]).
  • New dependencies are only imported inside functions that use them ([example][ex-import]).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

@mention-bot
Copy link
Copy Markdown

@andrey-git, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @fabaff and @turbokongen to be potential reviewers.

devices = []
try:
for dev in (
yield from client.async_get_devices(_INITIAL_FETCH_FIELDS)):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please wrap this in async_timeout.timeout to make sure that we don't wait forever.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is a default timeout on operations of 5 minutes: https://github.com/aio-libs/aiohttp/blob/master/aiohttp/client.py#L37

I'll pass in lower timeout.

Would it be cleaner if the client session additionally had a default read and connect timeouts? https://github.com/aio-libs/aiohttp/blob/master/aiohttp/client.py#L55

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are many things that can cause a request to take forever. If you look at the intro of the docs, they suggest to use async_timeout.timeout: http://aiohttp.readthedocs.io/en/stable/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

def max_temp(self):
"""Return the maximum temperature."""
return self._current_capabilities['temperatures'][
'C' if self.unit_of_measurement == TEMP_CELSIUS else 'F'][
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should not have to do these conversions yourself. If you return the unit that the device uses as temperature_unit, HASS will take care of converting it correctly.

(this comment applies to all other conversions too)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the device uses C internally, but the API uses the unit selected in the app. That's the unit I return in temperature_unit.

The device API also returns min/max temperature range in both C and F.
I'm picking an appropriate JSON field here, not converting anything.

The only place I'm converting units is current_temperature because that field is always in C unlike target_temperature which is according to temperature_unit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since both fields are available, I would suggest you just always pick C and let Home Assistant do the conversion if necessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually the JSON looks like this

"C": {"isNative": True, "values": [16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]},
"F": {"isNative": False, "values": [61, 63, 64, 66, 68, 70, 72, 73, 75, 77, 79, 81, 82, 84, 86]}}

So not all whole-F values are accepted.
I'll add a fix to make sure correct F temperature is set.

As for min and max - it would be safest to stick to the provided list. What is the advantage of converting?

"""Turn Sensibo unit on."""
yield from self._client.async_set_ac_state_property(
self._id, 'on', False)
yield from self.async_update_ha_state(True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should_poll is not defined and so defaults to True, this means that Hass will call this for you after calling any service. You can remove all these statements.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could you point me to the code where this happens?
I would like to get an immediate update, i.e not as part of 15s update cycle here: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/helpers/entity_component.py#L377

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

def async_update(self):
"""Retrieve latest state."""
try:
data = yield from self._client.async_get_device(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a timeout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added to _client constructor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That should be using async_timeout.timeout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

data = yield from self._client.async_get_device(
self._id, _FETCH_FIELDS)
self._do_update(data)
except aiohttp.client_exceptions.ClientConnectorError:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what about all the other errors? Shouldn't you just listen for the base error ClientError

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@balloob balloob merged commit 11dc724 into home-assistant:dev May 3, 2017
@andrey-git andrey-git deleted the sensibo branch May 3, 2017 15:33
@balloob balloob mentioned this pull request May 5, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Aug 12, 2017
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.

5 participants