Add min_temp and max_temp to MQTT climate device#14690
Add min_temp and max_temp to MQTT climate device#14690balloob merged 6 commits intohome-assistant:devfrom
Conversation
|
|
||
| state = self.hass.states.get(ENTITY_CLIMATE) | ||
| self.assertEqual(35, state.attributes.get('max_temp')) | ||
|
|
dgomes
left a comment
There was a problem hiding this comment.
I understand your clever use of the super class, but maybe we can improve the super class in this PR defining 7 and 35 as constants and using these constants as the defaults for config.get()
|
I wish I could say it was my cleverness, but I was simply doing some copypasta from the generic thermostat class. Any suggestions are welcome. |
|
Perhaps let's open a separate ticket/PR and fix the superclass issue (and refactor subclasses) in that? |
|
Would replace the super().min_temp with the imported DEFAULT_MIN_HUMITIDY. This would make things more explicit |
|
Cool; I'll take a crack at it once this one gets merged. |
|
I see things the other way round. The other PR should come first, then you rebase this one according to the changes, then this gets approved. |
|
OK, see #14721 |
| """Return the minimum temperature.""" | ||
| # pylint: disable=no-member | ||
| if self._min_temp: | ||
| return self._min_temp |
There was a problem hiding this comment.
So if the parent entity is converting the temperature to the internal temp_unit, I think we should do so here too, right?
There was a problem hiding this comment.
yeah, good point. missed that logic
There was a problem hiding this comment.
We should probably also fix whatever bugs were introduced in #14721 since I didn't consider that.
There was a problem hiding this comment.
Already went ahead in #14730
This is really confusing thanks to the lack of a consistent use of units cross platforms :(
| vol.Optional(CONF_PAYLOAD_ON, default="ON"): cv.string, | ||
| vol.Optional(CONF_PAYLOAD_OFF, default="OFF"): cv.string, | ||
|
|
||
| vol.Optional(CONF_MIN_TEMP): vol.Coerce(float), |
There was a problem hiding this comment.
So I think an even cleaner solution would be to write
vol.Optional(CONF_MIN_TEMP, default=DEFAULT_MIN_TEMP): vol.Coerce(float),The later, you could just write:
@property
def min_temp(self):
"""Return the minimum temperature."""
return self._min_tempThe voluptuous schema is where usually all default values should reside in (when there are config schemas). Having the default values in code usually leads to bugs one way or another.
There was a problem hiding this comment.
Banged my head against this too.
DEFAULT_MIN_TEMP is in CELCIUS, CONF_MIN_TEMP might not be... using the default=DEFAULT_MIN_TEMP leaves an innuendo on what is the unit of the temperature voluptuous returns :(
There was a problem hiding this comment.
Then again if I revert it to super().min_temp it will do the conversion according to convert_temperature() and return that value. Or implement that logic in each subclass?
| assert setup_component(self.hass, climate.DOMAIN, DEFAULT_CONFIG) | ||
|
|
||
| state = self.hass.states.get(ENTITY_CLIMATE) | ||
| self.assertEqual(7, state.attributes.get('min_temp')) |
There was a problem hiding this comment.
So these test cases are not really testing much. The tests on lines 56-57 already do test the defaults. It would, however be good that the configuration schema would be tested with something like
assert setup_component(self.hass, climate.DOMAIN, {
# ...
'min_temp': 10.0,
})
state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(10.0, state.attributes.get('min_temp'))| def max_temp(self): | ||
| """Return the maximum temperature.""" | ||
| # pylint: disable=no-member | ||
| return self._max_temp No newline at end of file |
| import homeassistant.helpers.config_validation as cv | ||
| from homeassistant.components.fan import (SPEED_LOW, SPEED_MEDIUM, | ||
| SPEED_HIGH) | ||
| from homeassistant.util.temperature import convert as convert_temperature |
There was a problem hiding this comment.
'homeassistant.util.temperature.convert as convert_temperature' imported but unused
| max_temp = state.attributes.get('max_temp') | ||
|
|
||
| self.assertIsInstance(max_temp, float) | ||
| self.assertEqual(60, max_temp) No newline at end of file |
| def max_temp(self): | ||
| """Return the maximum temperature.""" | ||
| # pylint: disable=no-member | ||
| return self._max_temp No newline at end of file |
| import homeassistant.helpers.config_validation as cv | ||
| from homeassistant.components.fan import (SPEED_LOW, SPEED_MEDIUM, | ||
| SPEED_HIGH) | ||
| from homeassistant.util.temperature import convert as convert_temperature |
There was a problem hiding this comment.
'homeassistant.util.temperature.convert as convert_temperature' imported but unused
| max_temp = state.attributes.get('max_temp') | ||
|
|
||
| self.assertIsInstance(max_temp, float) | ||
| self.assertEqual(60, max_temp) No newline at end of file |
* Add min_temp and max_temp to MQTT climate device * Add unit tests * Remove blank line * Fix unit tests & temp return values * PEP-8 fixes * Remove unused import
Description:
min_tempandmax_tempnow work with the MQTT climate device.Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5455
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed: