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

Fix deprecated contants #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 15 additions & 12 deletions custom_components/miheater/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

from homeassistant.components.climate import ClimateEntity, PLATFORM_SCHEMA
from homeassistant.components.climate.const import (
DOMAIN, HVAC_MODE_HEAT,HVAC_MODE_COOL, HVAC_MODE_OFF,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_FAN_MODE)
DOMAIN, HVACMode, ClimateEntityFeature)
from homeassistant.const import (
ATTR_TEMPERATURE, CONF_HOST, CONF_NAME, CONF_TOKEN, CONF_DEVICE_ID,
STATE_ON, STATE_OFF, TEMP_CELSIUS)
STATE_ON, STATE_OFF, UnitOfTemperature)
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity import generate_entity_id
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand All @@ -28,7 +27,7 @@

CONF_MODEL = 'model'
REQUIREMENTS = ['python-miio>=0.5.0']
SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE)
SUPPORT_FLAGS = (ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON)
SERVICE_SET_ROOM_TEMP = 'miheater_set_room_temperature'
PRECISION = 1
MIN_TEMP = 18
Expand Down Expand Up @@ -77,7 +76,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
DEVICE_MODEL = model

unique_id = "{}-{}".format(model, device_info.mac_address)
_LOGGER.warning("%s %s %s detected",
_LOGGER.info("%s %s %s detected",
model,
device_info.firmware_version,
device_info.hardware_version)
Expand Down Expand Up @@ -121,6 +120,9 @@ def __init__(self, device, name, model, unique_id, _hass):
self._attr_unique_id = unique_id
self.entity_id = generate_entity_id('climate.{}', unique_id, hass=_hass)
self.getAttrData()
# Disable turn on/off backwards compatibility for void log warning
self._enable_turn_on_off_backwards_compatibility = False

@property
def name(self):
"""Return the name of the device."""
Expand All @@ -133,21 +135,21 @@ def device(self):

@property
def hvac_mode(self):
return HVAC_MODE_HEAT if self._state['power'] else HVAC_MODE_OFF
return HVACMode.HEAT if self._state['power'] else HVACMode.OFF

@property
def hvac_modes(self):
return [HVAC_MODE_HEAT, HVAC_MODE_OFF]

return [HVACMode.HEAT, HVACMode.OFF]

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS

@property
def temperature_unit(self):
"""Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

# @property
# def precision(self):
Expand All @@ -174,6 +176,7 @@ def current_humidity(self):
def target_temperature_step(self):
"""Return the supported step of target temperature."""
return 1

def getAttrData(self):

try:
Expand Down Expand Up @@ -237,7 +240,7 @@ def max_temp(self):
async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
_LOGGER.warning("Setting temperature: %s", int(temperature))
_LOGGER.info("Setting temperature: %s", int(temperature))
if temperature is None:
_LOGGER.error("Wrong temperature: %s", temperature)
return
Expand Down Expand Up @@ -290,9 +293,9 @@ async def async_update(self):

async def async_set_hvac_mode(self, hvac_mode):
"""Set operation mode."""
if hvac_mode == HVAC_MODE_HEAT or hvac_mode == HVAC_MODE_COOL:
if hvac_mode == HVACMode.HEAT or hvac_mode == HVACMode.COOL:
await self.async_turn_on()
elif hvac_mode == HVAC_MODE_OFF:
elif hvac_mode == HVACMode.OFF:
await self.async_turn_off()
else:
_LOGGER.error("Unrecognized operation mode: %s", hvac_mode)