-
-
Notifications
You must be signed in to change notification settings - Fork 32k
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 min_temp and max_temp to MQTT climate device #14690
Conversation
|
||
state = self.hass.states.get(ENTITY_CLIMATE) | ||
self.assertEqual(35, state.attributes.get('max_temp')) | ||
|
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.
blank line at end of file
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, good point. missed that logic
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.
We should probably also fix whatever bugs were introduced in #14721 since I didn't consider that.
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.
Already went ahead in #14730
This is really confusing thanks to the lack of a consistent use of units cross platforms :(
@@ -116,6 +119,10 @@ | |||
vol.Optional(CONF_SEND_IF_OFF, default=True): cv.boolean, | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_temp
The 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
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 newline at end of file
@@ -26,6 +26,7 @@ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'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) |
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 newline at end of file
def max_temp(self): | ||
"""Return the maximum temperature.""" | ||
# pylint: disable=no-member | ||
return self._max_temp |
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 newline at end of file
@@ -26,6 +26,7 @@ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'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) |
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 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_temp
andmax_temp
now 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: