Skip to content

Add MQTT climate temperature unit#34066

Merged
emontnemery merged 5 commits intohome-assistant:devfrom
presslab-us:therm_unit
Apr 15, 2020
Merged

Add MQTT climate temperature unit#34066
emontnemery merged 5 commits intohome-assistant:devfrom
presslab-us:therm_unit

Conversation

@presslab-us
Copy link
Copy Markdown
Contributor

@presslab-us presslab-us commented Apr 11, 2020

Proposed change

Add unit_of_measurement to MQTT HVAC. This allows for a device to use a temperature unit other than the system unit.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

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

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

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@probot-home-assistant
Copy link
Copy Markdown

Hey there @home-assistant/core, @emontnemery, mind taking a look at this pull request as its been labeled with a integration (mqtt) you are listed as a codeowner for? Thanks!

Copy link
Copy Markdown
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

Looks good, just a couple of small comments.

CONF_TEMP_MAX = "max_temp"
CONF_TEMP_MIN = "min_temp"
CONF_TEMP_STEP = "temp_step"
CONF_TEMP_UNIT = "unit_of_measurement"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Import CONF_UNIT_OF_MEASUREMENT from homeassistant.const instead.

vol.Optional(CONF_TEMP_LOW_STATE_TOPIC): mqtt.valid_subscribe_topic,
vol.Optional(CONF_TEMP_STATE_TEMPLATE): cv.template,
vol.Optional(CONF_TEMP_STATE_TOPIC): mqtt.valid_subscribe_topic,
vol.Optional(CONF_TEMP_UNIT): cv.string,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use cv.temperature_unit

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 for reviewing! I changed it to cv.temperature_unit, but it doesn't work. The temperature_unit validator does not accept the degree symbol required when used as a unit of measurement.
https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/config_validation.py#L468-L475

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right, this is the purpose of cv.temperature_unit: in the MQTT discovery message or configuration.yaml, Cor F is specified, this is then transformed to °C or °F.

To make it more similar to other integrations which allows configuring temperature unit in the same way, change to use const.CONF_TEMPERATURE_UNIT instead of const.CONF_UNIT_OF_MEASUREMENT.

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.

As that change will basically rewrite this (small) pull request, I think I will just close this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the new functionality is good though. I did some adjustment, does it look OK?

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. Let me test it and get back to you. I find it curious that the temperature_unit climate property will work with either returning the degree symbol or without it. Which is technically correct?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The degree symbol is added by cv.temperature_unit when the config schema is validated. I think the purpose of cv.temperature_unit is to not have to write the degree symbol in config files which doesn't exist on most keyboards.

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 tested your changes and it works fine. Thanks for your help.

@emontnemery emontnemery merged commit e417535 into home-assistant:dev Apr 15, 2020
@emontnemery emontnemery changed the title Add MQTT climate unit of measurement Add MQTT climate temperature unit Apr 15, 2020
@lock lock Bot locked and limited conversation to collaborators Apr 19, 2020
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.

3 participants