Adjust modbus climate to use address/input_type (#51202)

This commit is contained in:
jan iversen 2021-05-28 17:57:14 +02:00 committed by GitHub
parent 88dce0ec8f
commit 538a189168
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 22 deletions

View file

@ -58,8 +58,6 @@ from .const import (
CONF_BYTESIZE,
CONF_CLIMATES,
CONF_CLOSE_COMM_ON_ERROR,
CONF_CURRENT_TEMP,
CONF_CURRENT_TEMP_REGISTER_TYPE,
CONF_DATA_COUNT,
CONF_DATA_TYPE,
CONF_FANS,
@ -124,12 +122,15 @@ BASE_COMPONENT_SCHEMA = vol.Schema(
CLIMATE_SCHEMA = BASE_COMPONENT_SCHEMA.extend(
{
vol.Required(CONF_CURRENT_TEMP): cv.positive_int,
vol.Required(CONF_ADDRESS): cv.positive_int,
vol.Optional(CONF_INPUT_TYPE, default=CALL_TYPE_REGISTER_HOLDING): vol.In(
[
CALL_TYPE_REGISTER_HOLDING,
CALL_TYPE_REGISTER_INPUT,
]
),
vol.Required(CONF_TARGET_TEMP): cv.positive_int,
vol.Optional(CONF_DATA_COUNT, default=2): cv.positive_int,
vol.Optional(
CONF_CURRENT_TEMP_REGISTER_TYPE, default=CALL_TYPE_REGISTER_HOLDING
): vol.In([CALL_TYPE_REGISTER_HOLDING, CALL_TYPE_REGISTER_INPUT]),
vol.Optional(CONF_DATA_TYPE, default=DATA_TYPE_FLOAT): vol.In(
[DATA_TYPE_INT, DATA_TYPE_UINT, DATA_TYPE_FLOAT, DATA_TYPE_CUSTOM]
),

View file

@ -11,7 +11,6 @@ from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.const import (
CONF_ADDRESS,
CONF_NAME,
CONF_OFFSET,
CONF_STRUCTURE,
@ -29,11 +28,8 @@ from .const import (
CALL_TYPE_REGISTER_HOLDING,
CALL_TYPE_WRITE_REGISTERS,
CONF_CLIMATES,
CONF_CURRENT_TEMP,
CONF_CURRENT_TEMP_REGISTER_TYPE,
CONF_DATA_COUNT,
CONF_DATA_TYPE,
CONF_INPUT_TYPE,
CONF_MAX_TEMP,
CONF_MIN_TEMP,
CONF_PRECISION,
@ -108,14 +104,8 @@ class ModbusThermostat(BasePlatform, RestoreEntity, ClimateEntity):
config: dict[str, Any],
) -> None:
"""Initialize the modbus thermostat."""
config[CONF_ADDRESS] = "0"
config[CONF_INPUT_TYPE] = ""
super().__init__(hub, config)
self._target_temperature_register = config[CONF_TARGET_TEMP]
self._current_temperature_register = config[CONF_CURRENT_TEMP]
self._current_temperature_register_type = config[
CONF_CURRENT_TEMP_REGISTER_TYPE
]
self._target_temperature = None
self._current_temperature = None
self._data_type = config[CONF_DATA_TYPE]
@ -212,7 +202,7 @@ class ModbusThermostat(BasePlatform, RestoreEntity, ClimateEntity):
CALL_TYPE_REGISTER_HOLDING, self._target_temperature_register
)
self._current_temperature = await self._async_read_register(
self._current_temperature_register_type, self._current_temperature_register
self._input_type, self._address
)
self.async_write_ha_state()

View file

@ -5,12 +5,12 @@ from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
from homeassistant.components.climate.const import HVAC_MODE_AUTO
from homeassistant.components.modbus.const import (
CONF_CLIMATES,
CONF_CURRENT_TEMP,
CONF_DATA_COUNT,
CONF_TARGET_TEMP,
)
from homeassistant.const import (
ATTR_TEMPERATURE,
CONF_ADDRESS,
CONF_NAME,
CONF_SCAN_INTERVAL,
CONF_SLAVE,
@ -38,7 +38,7 @@ async def test_config_climate(hass, do_options):
device_config = {
CONF_NAME: device_name,
CONF_TARGET_TEMP: 117,
CONF_CURRENT_TEMP: 117,
CONF_ADDRESS: 117,
CONF_SLAVE: 10,
**do_options,
}
@ -72,7 +72,7 @@ async def test_temperature_climate(hass, regs, expected):
CONF_NAME: climate_name,
CONF_SLAVE: 1,
CONF_TARGET_TEMP: 117,
CONF_CURRENT_TEMP: 117,
CONF_ADDRESS: 117,
CONF_DATA_COUNT: 2,
},
climate_name,
@ -96,7 +96,7 @@ async def test_service_climate_update(hass, mock_pymodbus):
{
CONF_NAME: "test",
CONF_TARGET_TEMP: 117,
CONF_CURRENT_TEMP: 117,
CONF_ADDRESS: 117,
CONF_SLAVE: 10,
}
]
@ -123,7 +123,7 @@ async def test_restore_state_climate(hass):
config_sensor = {
CONF_NAME: climate_name,
CONF_TARGET_TEMP: 117,
CONF_CURRENT_TEMP: 117,
CONF_ADDRESS: 117,
}
mock_restore_cache(
hass,