Skip to content

Commit

Permalink
fixed some depricated warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pwesters committed Jan 4, 2024
1 parent 8ff6f33 commit c78900e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 52 deletions.
49 changes: 19 additions & 30 deletions custom_components/watts_vision/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,25 @@

from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
CURRENT_HVAC_COOL,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
CURRENT_HVAC_OFF,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
ClimateEntityFeature,
HVACAction,
HVACMode,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_FAHRENHEIT
from homeassistant.const import UnitOfTemperature
from homeassistant.helpers.typing import HomeAssistantType

from .const import (
API_CLIENT,
DOMAIN,
PRESET_BOOST,
PRESET_COMFORT,
PRESET_DEFROST,
PRESET_ECO,
PRESET_MODE_MAP,
PRESET_MODE_REVERSE_MAP,
PRESET_OFF,
PRESET_PROGRAM_OFF,
PRESET_PROGRAM_ON,
PRESET_PROGRAM_OFF
)
from .watts_api import WattsApi

Expand Down Expand Up @@ -97,15 +89,17 @@ def name(self) -> str:

@property
def supported_features(self):
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
return (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)

@property
def temperature_unit(self) -> str:
return TEMP_FAHRENHEIT
return UnitOfTemperature.FAHRENHEIT

@property
def hvac_modes(self) -> list[str]:
return [HVAC_MODE_HEAT] + [HVAC_MODE_COOL] + [HVAC_MODE_OFF]
return [HVACMode.HEAT] + [HVACMode.COOL] + [HVACMode.OFF]

@property
def hvac_mode(self) -> str:
Expand Down Expand Up @@ -138,7 +132,6 @@ def device_info(self):
}

async def async_update(self):
# try:
smartHomeDevice = self.client.getDevice(self.smartHome, self.id)

self._attr_current_temperature = float(smartHomeDevice["temperature_air"]) / 10
Expand All @@ -151,27 +144,27 @@ async def async_update(self):

if smartHomeDevice["heating_up"] == "0":
if smartHomeDevice["gv_mode"] == "1":
self._attr_hvac_action = CURRENT_HVAC_OFF
self._attr_hvac_action = HVACAction.OFF
else:
self._attr_hvac_action = CURRENT_HVAC_IDLE
self._attr_hvac_action = HVACAction.IDLE
else:
if smartHomeDevice["heat_cool"] == "1":
self._attr_hvac_action = CURRENT_HVAC_COOL
self._attr_hvac_action = HVACAction.COOLING
else:
self._attr_hvac_action = CURRENT_HVAC_HEAT
self._attr_hvac_action = HVACAction.HEATING

if smartHomeDevice["heat_cool"] == "1":
self._attr_hvac_mode = HVAC_MODE_COOL
self._attr_hvac_mode = HVACMode.COOL
else:
self._attr_hvac_mode = HVAC_MODE_HEAT
self._attr_hvac_mode = HVACMode.HEAT
self._attr_preset_mode = PRESET_MODE_MAP[smartHomeDevice["gv_mode"]]

if smartHomeDevice["gv_mode"] == "0":
self._attr_target_temperature = (
float(smartHomeDevice["consigne_confort"]) / 10
)
elif smartHomeDevice["gv_mode"] == "1":
self._attr_hvac_mode = HVAC_MODE_OFF
self._attr_hvac_mode = HVACMode.OFF
self._attr_target_temperature = None
elif smartHomeDevice["gv_mode"] == "2":
self._attr_target_temperature = float(smartHomeDevice["consigne_hg"]) / 10
Expand Down Expand Up @@ -203,13 +196,9 @@ async def async_update(self):
)
self._attr_extra_state_attributes["gv_mode"] = smartHomeDevice["gv_mode"]

# except:
# self._available = False
# _LOGGER.exception("Error retrieving data.")

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode."""
if hvac_mode == HVAC_MODE_HEAT or hvac_mode == HVAC_MODE_COOL:
if hvac_mode == HVACMode.HEAT or hvac_mode == HVACMode.COOL:
value = "0"
if self._attr_extra_state_attributes["previous_gv_mode"] == "0":
value = str(
Expand Down Expand Up @@ -295,7 +284,7 @@ async def async_set_hvac_mode(self, hvac_mode):
)
await self.hass.async_add_executor_job(func)

if hvac_mode == HVAC_MODE_OFF:
if hvac_mode == HVACMode.OFF:
self._attr_extra_state_attributes[
"previous_gv_mode"
] = self._attr_extra_state_attributes["gv_mode"]
Expand Down
34 changes: 12 additions & 22 deletions custom_components/watts_vision/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
import logging
from typing import Callable, Optional

from homeassistant.components.sensor import SensorDeviceClass, SensorEntity, STATE_CLASS_MEASUREMENT
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import UnitOfTemperature
from homeassistant.helpers.typing import HomeAssistantType
from numpy import NaN

Expand Down Expand Up @@ -117,15 +121,10 @@ def device_info(self):
}

async def async_update(self):
# try:
smartHomeDevice = self.client.getDevice(self.smartHome, self.id)

self._state = PRESET_MODE_MAP[smartHomeDevice["gv_mode"]]

# except:
# self._available = False
# _LOGGER.exception("Error retrieving data.")


class WattsVisionTemperatureSensor(SensorEntity):
"""Representation of a Watts Vision temperature sensor."""
Expand Down Expand Up @@ -156,15 +155,15 @@ def state(self) -> Optional[str]:

@property
def state_class(self):
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT

@property
def device_class(self):
return SensorDeviceClass.TEMPERATURE

@property
def native_unit_of_measurement(self):
return TEMP_FAHRENHEIT
return UnitOfTemperature.FAHRENHEIT

@property
def device_info(self):
Expand All @@ -180,17 +179,13 @@ def device_info(self):
}

async def async_update(self):
# try:
smartHomeDevice = self.client.getDevice(self.smartHome, self.id)
if self.hass.config.units.temperature_unit == TEMP_CELSIUS:
if self.hass.config.units.temperature_unit == UnitOfTemperature.CELSIUS:
self._state = round(
(int(smartHomeDevice["temperature_air"]) - 320) * 5 / 9 / 10, 1
)
else:
self._state = int(smartHomeDevice["temperature_air"]) / 10
# except:
# self._available = False
# _LOGGER.exception("Error retrieving data.")


class WattsVisionSetTemperatureSensor(SensorEntity):
Expand Down Expand Up @@ -222,15 +217,15 @@ def state(self) -> Optional[str]:

@property
def state_class(self):
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT

@property
def device_class(self):
return SensorDeviceClass.TEMPERATURE

@property
def native_unit_of_measurement(self):
return TEMP_FAHRENHEIT
return UnitOfTemperature.FAHRENHEIT

@property
def device_info(self):
Expand All @@ -246,7 +241,6 @@ def device_info(self):
}

async def async_update(self):
# try:
smartHomeDevice = self.client.getDevice(self.smartHome, self.id)

if smartHomeDevice["gv_mode"] == "0":
Expand All @@ -262,11 +256,7 @@ async def async_update(self):
if smartHomeDevice["gv_mode"] == "11" or smartHomeDevice["gv_mode"] == "8":
self._state = smartHomeDevice["consigne_manuel"]
if self._state != NaN:
if self.hass.config.units.temperature_unit == TEMP_CELSIUS:
if self.hass.config.units.temperature_unit == UnitOfTemperature.CELSIUS:
self._state = round((int(self._state) - 320) * 5 / 9 / 10, 1)
else:
self._state = int(self._state) / 10

# except:
# self._available = False
# _LOGGER.exception("Error retrieving data.")

0 comments on commit c78900e

Please sign in to comment.