Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove HA deprecated constants #203

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ dmypy.json
# PyDev Eclipse projects
.project
.pydevproject

# Pycharm
.idea/
38 changes: 15 additions & 23 deletions custom_components/daikin_residential/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,15 @@
ATTR_HVAC_MODE,
ATTR_PRESET_MODE,
ATTR_SWING_MODE,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
HVAC_MODE_OFF,
PRESET_AWAY,
PRESET_COMFORT,
PRESET_BOOST,
PRESET_ECO,
PRESET_NONE,
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_SWING_MODE,
ClimateEntityFeature,
HVACMode
)
from homeassistant.const import ATTR_TEMPERATURE, CONF_HOST, CONF_NAME, TEMP_CELSIUS
from homeassistant.const import ATTR_TEMPERATURE, CONF_HOST, CONF_NAME, UnitOfTemperature
import homeassistant.helpers.config_validation as cv

from .const import (
Expand All @@ -36,7 +28,7 @@
ATTR_ON_OFF,
ATTR_STATE_OFF,
ATTR_STATE_ON,
ATTR_TARGET_TEMPERATURE,
ATTR_TARGET_TEMPERATURE
)

_LOGGER = logging.getLogger(__name__)
Expand All @@ -49,12 +41,12 @@
PRESET_MODES = {PRESET_BOOST, PRESET_COMFORT, PRESET_ECO, PRESET_AWAY}

HA_HVAC_TO_DAIKIN = {
HVAC_MODE_FAN_ONLY: "fanOnly",
HVAC_MODE_DRY: "dry",
HVAC_MODE_COOL: "cooling",
HVAC_MODE_HEAT: "heating",
HVAC_MODE_HEAT_COOL: "auto",
HVAC_MODE_OFF: "off",
HVACMode.FAN_ONLY: "fanOnly",
HVACMode.DRY: "dry",
HVACMode.COOL: "cooling",
HVACMode.HEAT: "heating",
HVACMode.HEAT_COOL: "auto",
HVACMode.OFF: "off",
}


Expand Down Expand Up @@ -99,20 +91,20 @@ def __init__(self, device):
ATTR_SWING_MODE: self._device.swing_modes,
}

self._supported_features = SUPPORT_TARGET_TEMPERATURE
self._supported_features = ClimateEntityFeature.TARGET_TEMPERATURE

self._supported_preset_modes = [PRESET_NONE]
self._current_preset_mode = PRESET_NONE
for mode in PRESET_MODES:
if self._device.support_preset_mode(mode):
self._supported_preset_modes.append(mode)
self._supported_features |= SUPPORT_PRESET_MODE
self._supported_features |= ClimateEntityFeature.PRESET_MODE

if self._device.support_fan_rate:
self._supported_features |= SUPPORT_FAN_MODE
self._supported_features |= ClimateEntityFeature.FAN_MODE

if self._device.support_swing_mode:
self._supported_features |= SUPPORT_SWING_MODE
self._supported_features |= ClimateEntityFeature.SWING_MODE

async def _set(self, settings):
"""Set device settings using API."""
Expand Down Expand Up @@ -166,7 +158,7 @@ def unique_id(self):
@property
def temperature_unit(self):
"""Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

@property
def current_temperature(self):
Expand Down
30 changes: 13 additions & 17 deletions custom_components/daikin_residential/const.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
"""Constants for Daikin Residential Controller."""

from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import (
CONF_DEVICE_CLASS,
CONF_TOKEN,
CONF_ICON,
CONF_NAME,
CONF_TYPE,
CONF_UNIT_OF_MEASUREMENT,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_SIGNAL_STRENGTH,
ENERGY_KILO_WATT_HOUR,
TEMP_CELSIUS,
PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
UnitOfTemperature,
UnitOfEnergy
)

DOMAIN = "daikin_residential"
Expand Down Expand Up @@ -136,39 +132,39 @@
ATTR_INSIDE_TEMPERATURE: {
CONF_NAME: "Inside Temperature",
CONF_TYPE: SENSOR_TYPE_TEMPERATURE,
CONF_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
CONF_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
CONF_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
CONF_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
},
ATTR_OUTSIDE_TEMPERATURE: {
CONF_NAME: "Outside Temperature",
CONF_TYPE: SENSOR_TYPE_TEMPERATURE,
CONF_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
CONF_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
CONF_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
CONF_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
},
ATTR_ROOM_HUMIDITY: {
CONF_NAME: "Room Humidity",
CONF_TYPE: SENSOR_TYPE_HUMIDITY,
CONF_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY,
CONF_DEVICE_CLASS: SensorDeviceClass.HUMIDITY,
CONF_UNIT_OF_MEASUREMENT: PERCENTAGE,
},
ATTR_COOL_ENERGY: {
CONF_NAME: "Cool Energy Consumption",
CONF_TYPE: SENSOR_TYPE_ENERGY,
CONF_ICON: "mdi:snowflake",
CONF_DEVICE_CLASS: DEVICE_CLASS_ENERGY,
CONF_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
CONF_DEVICE_CLASS: SensorDeviceClass.ENERGY,
CONF_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR,
},
ATTR_HEAT_ENERGY: {
CONF_NAME: "Heat Energy Consumption",
CONF_TYPE: SENSOR_TYPE_ENERGY,
CONF_ICON: "mdi:fire",
CONF_DEVICE_CLASS: DEVICE_CLASS_ENERGY,
CONF_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
CONF_DEVICE_CLASS: SensorDeviceClass.ENERGY,
CONF_UNIT_OF_MEASUREMENT: UnitOfEnergy.KILO_WATT_HOUR,
},
ATTR_WIFI_STRENGTH: {
CONF_NAME: "WiFi Strength",
CONF_TYPE: SENSOR_TYPE_GATEWAY_DIAGNOSTIC,
CONF_DEVICE_CLASS: DEVICE_CLASS_SIGNAL_STRENGTH,
CONF_DEVICE_CLASS: SensorDeviceClass.SIGNAL_STRENGTH,
CONF_UNIT_OF_MEASUREMENT: SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
},
ATTR_WIFI_SSID: {
Expand Down
29 changes: 12 additions & 17 deletions custom_components/daikin_residential/daikin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,14 @@
ATTR_FAN_MODE,
ATTR_PRESET_MODE,
FAN_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
HVAC_MODE_OFF,
PRESET_AWAY,
PRESET_COMFORT,
PRESET_BOOST,
PRESET_ECO,
PRESET_NONE,
DEFAULT_MAX_TEMP,
DEFAULT_MIN_TEMP,
HVACMode
)

_LOGGER = logging.getLogger(__name__)
Expand All @@ -65,12 +60,12 @@
}

DAIKIN_HVAC_TO_HA = {
"fanOnly": HVAC_MODE_FAN_ONLY,
"dry": HVAC_MODE_DRY,
"cooling": HVAC_MODE_COOL,
"heating": HVAC_MODE_HEAT,
"auto": HVAC_MODE_HEAT_COOL,
"off": HVAC_MODE_OFF,
"fanOnly": HVACMode.FAN_ONLY,
"dry": HVACMode.DRY,
"cooling": HVACMode.COOL,
"heating": HVACMode.HEAT,
"auto": HVACMode.HEAT_COOL,
"off": HVACMode.OFF
}

DAIKIN_FAN_TO_HA = {"auto": FAN_AUTO, "quiet": FAN_QUIET}
Expand Down Expand Up @@ -142,25 +137,25 @@ def mac(self):
@property
def hvac_mode(self):
"""Return current HVAC mode."""
mode = HVAC_MODE_OFF
mode = HVACMode.OFF
if self.getValue(ATTR_ON_OFF) != ATTR_STATE_OFF:
mode = self.getValue(ATTR_OPERATION_MODE)
return DAIKIN_HVAC_TO_HA.get(mode, HVAC_MODE_HEAT_COOL)
return DAIKIN_HVAC_TO_HA.get(mode, HVACMode.HEAT_COOL)

@property
def hvac_modes(self):
"""Return the list of available HVAC modes."""
modes = [HVAC_MODE_OFF]
modes = [HVACMode.OFF]
for mode in self.getValidValues(ATTR_OPERATION_MODE):
modes.append(DAIKIN_HVAC_TO_HA[mode])
return modes

async def async_set_hvac_mode(self, hvac_mode):
"""Set HVAC mode."""
if hvac_mode == HVAC_MODE_OFF:
if hvac_mode == HVACMode.OFF:
return await self.setValue(ATTR_ON_OFF, ATTR_STATE_OFF)
else:
if self.hvac_mode == HVAC_MODE_OFF:
if self.hvac_mode == HVACMode.OFF:
await self.setValue(ATTR_ON_OFF, ATTR_STATE_ON)
return await self.setValue(ATTR_OPERATION_MODE, hvac_mode)

Expand Down
9 changes: 4 additions & 5 deletions custom_components/daikin_residential/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
)
from homeassistant.components.sensor import (
SensorEntity,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorStateClass
)

from homeassistant.helpers.entity import EntityCategory
Expand Down Expand Up @@ -188,7 +187,7 @@ def state(self):

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


class DaikinEnergySensor(DaikinSensor):
Expand All @@ -205,7 +204,7 @@ def state(self):

@property
def state_class(self):
return STATE_CLASS_TOTAL_INCREASING
return SensorStateClass.TOTAL_INCREASING


class DaikinGatewaySensor(DaikinSensor):
Expand All @@ -232,7 +231,7 @@ def state(self):
@property
def state_class(self):
if self._device_attribute == ATTR_WIFI_STRENGTH:
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT
else:
return None

Expand Down