Limych / ha-average

Average Sensor for Home Assistant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sensor fails if temperature unit is "f" vs "F"

xstrex opened this issue · comments

Environment

  • Home Assistant Core release with the issue: 2022.10.4
  • This custom component release with the issue: 2.3.0
  • Last working this custom component release (if known):
  • Operating environment (Home Assistant/Supervisor/Docker/venv): Docker

Describe the bug

Configuration.yaml

  - platform: average
    name: 'home temperature'
    entities:
      - sensor.pure_cool_link_temperature
      - sensor.pure_hot_cool_link_temperature
      - sensor.thermostat_temp
      - sensor.motion_temp

Steps to Reproduce

add a sensor with the unit_of_measurement set to '°f'

Expected behavior

Debug log


2022-10-19 13:42:54.228 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/average/sensor.py", line 212, in async_sensor_state_listener
    await self._async_update_state()
  File "/config/custom_components/average/sensor.py", line 463, in _async_update_state
    value = self._get_state_value(state)
  File "/config/custom_components/average/sensor.py", line 267, in _get_state_value
    state = self._get_temperature(state) if self._temperature_mode else state.state
  File "/config/custom_components/average/sensor.py", line 258, in _get_temperature
    temperature = convert_temperature(float(temperature), entity_unit, ha_unit)
  File "/usr/src/homeassistant/homeassistant/util/temperature.py", line 48, in convert
    return TemperatureConverter.convert(temperature, from_unit, to_unit)
  File "/usr/src/homeassistant/homeassistant/util/unit_conversion.py", line 314, in convert
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: °f is not a recognized temperature unit.


Additional context

I see 2 solutions here; either you make sure that every unit_of_measurement if using temperature is set to '°F', OR the developer adjusts the code to support a unit_of_measurement of either '°f' or '°F'.

The sensor does not analyze units to determine whether they are temperature units. This is done by the HA core. Inside HA there is only one designation option for temperature in Fahrenheit. All other options are not considered correct.

If you want to change this, please contact the HA core developers.