1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-23 20:39:01 +00:00

Fix homekit: temperature calculation (#12720)

This commit is contained in:
cdce8p
2018-02-26 22:29:52 +01:00
committed by Pascal Vizeli
parent 10570f5ad6
commit 6a665ffb84
2 changed files with 7 additions and 8 deletions

View File

@@ -2,7 +2,7 @@
import logging
from homeassistant.const import (
STATE_UNKNOWN, ATTR_UNIT_OF_MEASUREMENT, TEMP_FAHRENHEIT, TEMP_CELSIUS)
ATTR_UNIT_OF_MEASUREMENT, TEMP_FAHRENHEIT, TEMP_CELSIUS)
from homeassistant.helpers.event import async_track_state_change
from . import TYPES
@@ -21,21 +21,19 @@ def calc_temperature(state, unit=TEMP_CELSIUS):
Always return temperature as Celsius value.
Conversion is handled on the device.
"""
if state == STATE_UNKNOWN:
try:
value = float(state)
except ValueError:
return None
if unit == TEMP_FAHRENHEIT:
value = round((float(state) - 32) / 1.8, 2)
else:
value = float(state)
return value
return round((value - 32) / 1.8, 2) if unit == TEMP_FAHRENHEIT else value
@TYPES.register('TemperatureSensor')
class TemperatureSensor(HomeAccessory):
"""Generate a TemperatureSensor accessory for a temperature sensor.
Sensor entity must return temperature in °C, °F or STATE_UNKNOWN.
Sensor entity must return temperature in °C, °F.
"""
def __init__(self, hass, entity_id, display_name):