diff --git a/custom_components/watts_vision/manifest.json b/custom_components/watts_vision/manifest.json index 3b42d0c..d6197f4 100644 --- a/custom_components/watts_vision/manifest.json +++ b/custom_components/watts_vision/manifest.json @@ -8,5 +8,5 @@ "iot_class": "cloud_polling", "name": "Watts Vision", "requirements": [], - "version": "0.2.3" + "version": "0.2.4" } diff --git a/custom_components/watts_vision/sensor.py b/custom_components/watts_vision/sensor.py index 30ff620..93cb930 100644 --- a/custom_components/watts_vision/sensor.py +++ b/custom_components/watts_vision/sensor.py @@ -1,10 +1,12 @@ """Watts Vision sensor platform.""" from datetime import timedelta import logging +import math from typing import Callable, Optional -from homeassistant.components.sensor import SensorEntity +from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.config_entries import ConfigEntry +from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.helpers.typing import HomeAssistantType from numpy import NaN @@ -152,15 +154,11 @@ def state(self) -> Optional[str]: @property def device_class(self): - return "temperature" + return SensorDeviceClass.TEMPERATURE @property def native_unit_of_measurement(self): - return "°F" - - @property - def unit_of_measurement(self): - return "°F" + return TEMP_FAHRENHEIT @property def device_info(self): @@ -177,7 +175,10 @@ def device_info(self): async def async_update(self): # try: smartHomeDevice = self.client.getDevice(self.smartHome, self.id) - self._state = int(smartHomeDevice["temperature_air"]) / 10 + if self.hass.config.units.temperature_unit == TEMP_CELSIUS: + self._state = math.floor(((float(smartHomeDevice["temperature_air"]) / 10) - 32) / 1.8 * 10) / 10 + else: + self._state = float(smartHomeDevice["temperature_air"]) / 10 # except: # self._available = False # _LOGGER.exception("Error retrieving data.") @@ -211,15 +212,11 @@ def state(self) -> Optional[str]: @property def device_class(self): - return "temperature" + return SensorDeviceClass.TEMPERATURE @property def native_unit_of_measurement(self): - return "°F" - - @property - def unit_of_measurement(self): - return "°F" + return TEMP_FAHRENHEIT @property def device_info(self): @@ -238,17 +235,32 @@ async def async_update(self): smartHomeDevice = self.client.getDevice(self.smartHome, self.id) if smartHomeDevice["gv_mode"] == "0": - self._state = int(smartHomeDevice["consigne_confort"]) / 10 + if self.hass.config.units.temperature_unit == TEMP_CELSIUS: + self._state = math.floor(((float(smartHomeDevice["consigne_confort"]) / 10) - 32) / 1.8 * 10) / 10 + else: + self._state = float(smartHomeDevice["consigne_confort"]) / 10 if smartHomeDevice["gv_mode"] == "1": self._state = NaN if smartHomeDevice["gv_mode"] == "2": - self._state = int(smartHomeDevice["consigne_hg"]) / 10 + if self.hass.config.units.temperature_unit == TEMP_CELSIUS: + self._state = math.floor(((float(smartHomeDevice["consigne_hg"]) / 10) - 32) / 1.8 * 10) / 10 + else: + self._state = float(smartHomeDevice["consigne_hg"]) / 10 if smartHomeDevice["gv_mode"] == "3": - self._state = int(smartHomeDevice["consigne_eco"]) / 10 + if self.hass.config.units.temperature_unit == TEMP_CELSIUS: + self._state = math.floor(((float(smartHomeDevice["consigne_eco"]) / 10) - 32) / 1.8 * 10) / 10 + else: + self._state = float(smartHomeDevice["consigne_eco"]) / 10 if smartHomeDevice["gv_mode"] == "4": - self._state = int(smartHomeDevice["consigne_boost"]) / 10 + if self.hass.config.units.temperature_unit == TEMP_CELSIUS: + self._state = math.floor(((float(smartHomeDevice["consigne_boost"]) / 10) - 32) / 1.8 * 10) / 10 + else: + self._state = float(smartHomeDevice["consigne_boost"]) / 10 if smartHomeDevice["gv_mode"] == "11": - self._state = int(smartHomeDevice["consigne_manuel"]) / 10 + if self.hass.config.units.temperature_unit == TEMP_CELSIUS: + self._state = math.floor(((float(smartHomeDevice["consigne_manuel"]) / 10) - 32) / 1.8 * 10) / 10 + else: + self._state = float(smartHomeDevice["consigne_manuel"]) / 10 # except: # self._available = False