Add Sensibo climate platform#7379
Conversation
|
@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)): |
There was a problem hiding this comment.
Please wrap this in async_timeout.timeout to make sure that we don't wait forever.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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/
| def max_temp(self): | ||
| """Return the maximum temperature.""" | ||
| return self._current_capabilities['temperatures'][ | ||
| 'C' if self.unit_of_measurement == TEMP_CELSIUS else 'F'][ |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Since both fields are available, I would suggest you just always pick C and let Home Assistant do the conversion if necessary.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Have a look at the service handler: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/climate/__init__.py#L274-L287
| def async_update(self): | ||
| """Retrieve latest state.""" | ||
| try: | ||
| data = yield from self._client.async_get_device( |
There was a problem hiding this comment.
Added to _client constructor
There was a problem hiding this comment.
That should be using async_timeout.timeout.
| data = yield from self._client.async_get_device( | ||
| self._id, _FETCH_FIELDS) | ||
| self._do_update(data) | ||
| except aiohttp.client_exceptions.ClientConnectorError: |
There was a problem hiding this comment.
what about all the other errors? Shouldn't you just listen for the base error ClientError
Description:
Add Sensibo a/c remote as a climate platform.
To make it work correctly also added a new
target_temp_stepattribute 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):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable ([example][ex-requir]).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.