Remove temperature unit changes

This commit is contained in:
alexanv1 2022-02-15 23:26:24 -08:00
parent 244778edc0
commit 5a1f2fc69f
4 changed files with 22 additions and 43 deletions

View File

@ -13,8 +13,3 @@ RETRY_OFFLINE_COUNT = 5
SERVICE_SET_TIMER = "set_timer"
SERVICE_CLEAR_TIMER = "clear_timer"
SERVICE_SET_INT_VALUE = "set_int_value"
# Prevent Home Assistant automatic temperature conversions by overriding TEMP_CELCIUS, TEMP_FAHRENHEIT
# This makes sure that the values shows in the UI match device preferences bypassing the automatic conversion to whatever the Home Assistant default is set to
TEMP_CELSIUS = "\u2103"
TEMP_FAHRENHEIT = "\u2109"

View File

@ -1,7 +1,6 @@
from gehomesdk import ErdCode
from ...devices import ApplianceApi
from ..common import GeErdNumber
from ...const import TEMP_CELSIUS
from .ge_ccm_cached_value import GeCcmCachedValue
class GeCcmBrewTemperatureNumber(GeErdNumber, GeCcmCachedValue):
@ -20,10 +19,4 @@ class GeCcmBrewTemperatureNumber(GeErdNumber, GeCcmCachedValue):
@property
def brew_temperature(self) -> int:
value = self.value
if self.unit_of_measurement == TEMP_CELSIUS:
# Convert to Fahrenheit
value = int(round(value * 9/5) + 32)
return value
return self.value

View File

@ -5,11 +5,11 @@ from homeassistant.components.number import NumberEntity
from homeassistant.const import (
DEVICE_CLASS_TEMPERATURE,
TEMP_FAHRENHEIT,
)
from gehomesdk import ErdCodeType, ErdCodeClass, ErdMeasurementUnits
from gehomesdk import ErdCodeType, ErdCodeClass
from .ge_erd_entity import GeErdEntity
from ...devices import ApplianceApi
from ...const import TEMP_CELSIUS, TEMP_FAHRENHEIT
_LOGGER = logging.getLogger(__name__)
@ -74,11 +74,7 @@ class GeErdNumber(GeErdEntity, NumberEntity):
return self._mode
def _convert_value_from_device(self, value):
"""Convert to expected temperature units and data type"""
if (self._get_uom() == TEMP_CELSIUS):
# Convert to Celcius
value = (value - 32 ) * 5/9
"""Convert to expected data type"""
if self._data_type == ErdDataType.INT:
return int(round(value))
@ -93,13 +89,10 @@ class GeErdNumber(GeErdEntity, NumberEntity):
return self._uom_override
if self.device_class == DEVICE_CLASS_TEMPERATURE:
if self._measurement_system == ErdMeasurementUnits.METRIC:
# Actual data from API is always in Fahrenhreit but since Device preferences are set to Celcius
# we return Celcius here and will do the conversion ourselves
return TEMP_CELSIUS
else:
return TEMP_FAHRENHEIT
#NOTE: it appears that the API only sets temperature in Fahrenheit,
#so we'll hard code this UOM instead of using the device configured
#settings
return TEMP_FAHRENHEIT
return None
@ -126,10 +119,6 @@ class GeErdNumber(GeErdEntity, NumberEntity):
async def async_set_value(self, value):
"""Sets the ERD value, assumes that the data type is correct"""
if self._get_uom() == TEMP_CELSIUS:
# Convert to Fahrenheit
value = (value * 9/5) + 32
if self._data_type == ErdDataType.INT:
value = int(round(value))

View File

@ -9,11 +9,11 @@ from homeassistant.const import (
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_POWER_FACTOR,
TEMP_FAHRENHEIT,
)
from gehomesdk import ErdCodeType, ErdCodeClass, ErdMeasurementUnits
from gehomesdk import ErdCodeType, ErdCodeClass
from .ge_erd_entity import GeErdEntity
from ...devices import ApplianceApi
from ...const import TEMP_CELSIUS, TEMP_FAHRENHEIT
_LOGGER = logging.getLogger(__name__)
@ -69,18 +69,17 @@ class GeErdSensor(GeErdEntity, SensorEntity):
@property
def _temp_units(self) -> Optional[str]:
# Return the unit from device preferences
if self._measurement_system == ErdMeasurementUnits.METRIC:
return TEMP_CELSIUS
#based on testing, all API values are in Fahrenheit, so we'll redefine
#this property to be the configured temperature unit and set the native
#unit differently
return self.api.hass.config.units.temperature_unit
return TEMP_FAHRENHEIT
#if self._measurement_system == ErdMeasurementUnits.METRIC:
# return TEMP_CELSIUS
#return TEMP_FAHRENHEIT
def _convert_numeric_value_from_device(self, value):
"""Convert to expected temperature units and data type"""
if (self._get_uom() == TEMP_CELSIUS):
# Convert to Celcius since device always returns temperature in Fahrenheit regardless of device preferences
value = (value - 32 ) * 5/9
"""Convert to expected data type"""
if self._data_type == ErdDataType.INT:
return int(round(value))
@ -99,7 +98,10 @@ class GeErdSensor(GeErdEntity, SensorEntity):
in [ErdCodeClass.RAW_TEMPERATURE, ErdCodeClass.NON_ZERO_TEMPERATURE]
or self.device_class == DEVICE_CLASS_TEMPERATURE
):
return self._temp_units
#NOTE: it appears that the API only sets temperature in Fahrenheit,
#so we'll hard code this UOM instead of using the device configured
#settings
return TEMP_FAHRENHEIT
if (
self.erd_code_class == ErdCodeClass.BATTERY
or self.device_class == DEVICE_CLASS_BATTERY