Skip to content

Commit

Permalink
temporary fix for conversion F to C
Browse files Browse the repository at this point in the history
  • Loading branch information
pwesters committed Apr 21, 2022
1 parent be2a0d0 commit a40e550
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion custom_components/watts_vision/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"name": "Watts Vision",
"requirements": [],
"version": "0.2.3"
"version": "0.2.4"
}
50 changes: 31 additions & 19 deletions custom_components/watts_vision/sensor.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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.")
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit a40e550

Please sign in to comment.