Use climate enums in modbus (#70693)

This commit is contained in:
epenet 2022-04-26 09:18:00 +02:00 committed by GitHub
parent 20f7e2f4d2
commit 09393d6f64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -5,8 +5,8 @@ from datetime import datetime
import struct
from typing import Any
from homeassistant.components.climate import ClimateEntity, ClimateEntityFeature
from homeassistant.components.climate.const import HVAC_MODE_AUTO
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import ClimateEntityFeature, HVACMode
from homeassistant.const import (
ATTR_TEMPERATURE,
CONF_NAME,
@ -60,6 +60,8 @@ async def async_setup_platform(
class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
"""Representation of a Modbus Thermostat."""
_attr_hvac_mode = HVACMode.AUTO
_attr_hvac_modes = [HVACMode.AUTO]
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
def __init__(
@ -72,8 +74,6 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
self._target_temperature_register = config[CONF_TARGET_TEMP]
self._unit = config[CONF_TEMPERATURE_UNIT]
self._attr_hvac_mode = HVAC_MODE_AUTO
self._attr_hvac_modes = [HVAC_MODE_AUTO]
self._attr_current_temperature = None
self._attr_target_temperature = None
self._attr_temperature_unit = (
@ -94,7 +94,7 @@ class ModbusThermostat(BaseStructPlatform, RestoreEntity, ClimateEntity):
if state and state.attributes.get(ATTR_TEMPERATURE):
self._attr_target_temperature = float(state.attributes[ATTR_TEMPERATURE])
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set new target hvac mode."""
# Home Assistant expects this method.
# We'll keep it here to avoid getting exceptions.

View file

@ -2,7 +2,7 @@
import pytest
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
from homeassistant.components.climate.const import HVAC_MODE_AUTO
from homeassistant.components.climate.const import HVACMode
from homeassistant.components.modbus.const import (
CONF_CLIMATES,
CONF_DATA_TYPE,
@ -223,7 +223,7 @@ test_value.attributes = {ATTR_TEMPERATURE: 37}
async def test_restore_state_climate(hass, mock_test_state, mock_modbus):
"""Run test for sensor restore state."""
state = hass.states.get(ENTITY_ID)
assert state.state == HVAC_MODE_AUTO
assert state.state == HVACMode.AUTO
assert state.attributes[ATTR_TEMPERATURE] == 37