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

Add min_temp and max_temp to MQTT climate device #14690

Merged
merged 6 commits into from
Jun 7, 2018

Conversation

PhilRW
Copy link
Contributor

@PhilRW PhilRW commented May 30, 2018

Description:

min_temp and max_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):

climate:
  - platform: mqtt
    name: Study
    min_temp: 40
    max_temp: 90
    current_temperature_topic: /sensors/hvac_study/current_temp
    temperature_command_topic: /sensors/hvac_study/target_temp

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:


state = self.hass.states.get(ENTITY_CLIMATE)
self.assertEqual(35, state.attributes.get('max_temp'))

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

Copy link
Contributor

@dgomes dgomes left a 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()

@PhilRW
Copy link
Contributor Author

PhilRW commented May 30, 2018

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.

@PhilRW
Copy link
Contributor Author

PhilRW commented May 30, 2018

Perhaps let's open a separate ticket/PR and fix the superclass issue (and refactor subclasses) in that?

@PhilRW
Copy link
Contributor Author

PhilRW commented May 31, 2018

@dgomes Perhaps something like this?

@dgomes
Copy link
Contributor

dgomes commented May 31, 2018

Would replace the super().min_temp with the imported DEFAULT_MIN_HUMITIDY.

This would make things more explicit

@PhilRW
Copy link
Contributor Author

PhilRW commented May 31, 2018

Cool; I'll take a crack at it once this one gets merged.

@dgomes
Copy link
Contributor

dgomes commented May 31, 2018

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.

@PhilRW
Copy link
Contributor Author

PhilRW commented May 31, 2018

OK, see #14721

"""Return the minimum temperature."""
# pylint: disable=no-member
if self._min_temp:
return self._min_temp
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Copy link
Contributor

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 :(

home-assistant/architecture#10

@@ -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),
Copy link
Member

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.

Copy link
Contributor

@dgomes dgomes May 31, 2018

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 :(

Copy link
Contributor Author

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'))
Copy link
Member

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'))

@dgomes dgomes mentioned this pull request May 31, 2018
8 tasks
@PhilRW PhilRW requested review from andrey-git, cdce8p and a team as code owners June 1, 2018 15:37
def max_temp(self):
"""Return the maximum temperature."""
# pylint: disable=no-member
return self._max_temp

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

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)

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

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

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)

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

@cdce8p cdce8p removed their request for review June 1, 2018 19:31
@balloob balloob merged commit bb4d177 into home-assistant:dev Jun 7, 2018
@ghost ghost removed the Ready for review label Jun 7, 2018
@balloob balloob mentioned this pull request Jun 22, 2018
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
* 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
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
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.

6 participants