diff --git a/homeassistant/components/modbus/__init__.py b/homeassistant/components/modbus/__init__.py index 0108c37a10b..920188603fc 100644 --- a/homeassistant/components/modbus/__init__.py +++ b/homeassistant/components/modbus/__init__.py @@ -55,7 +55,6 @@ from .const import ( # noqa: F401 CALL_TYPE_DISCRETE, CALL_TYPE_REGISTER_HOLDING, CALL_TYPE_REGISTER_INPUT, - CALL_TYPE_WRITE_REGISTER, CALL_TYPE_X_COILS, CALL_TYPE_X_REGISTER_HOLDINGS, CONF_BAUDRATE, @@ -64,7 +63,6 @@ from .const import ( # noqa: F401 CONF_CLOSE_COMM_ON_ERROR, CONF_DATA_TYPE, CONF_FANS, - CONF_HUB, CONF_HVAC_MODE_AUTO, CONF_HVAC_MODE_COOL, CONF_HVAC_MODE_DRY, diff --git a/homeassistant/components/modbus/const.py b/homeassistant/components/modbus/const.py index 3b565e91f92..e509577267c 100644 --- a/homeassistant/components/modbus/const.py +++ b/homeassistant/components/modbus/const.py @@ -16,13 +16,8 @@ CONF_BAUDRATE = "baudrate" CONF_BYTESIZE = "bytesize" CONF_CLIMATES = "climates" CONF_CLOSE_COMM_ON_ERROR = "close_comm_on_error" -CONF_COILS = "coils" -CONF_CURRENT_TEMP = "current_temp_register" -CONF_CURRENT_TEMP_REGISTER_TYPE = "current_temp_register_type" CONF_DATA_TYPE = "data_type" CONF_FANS = "fans" -CONF_HUB = "hub" -CONF_INPUTS = "inputs" CONF_INPUT_TYPE = "input_type" CONF_LAZY_ERROR = "lazy_error_count" CONF_MAX_TEMP = "max_temp" @@ -32,9 +27,6 @@ CONF_MIN_VALUE = "min_value" CONF_MSG_WAIT = "message_wait_milliseconds" CONF_NAN_VALUE = "nan_value" CONF_PARITY = "parity" -CONF_REGISTER = "register" -CONF_REGISTER_TYPE = "register_type" -CONF_REGISTERS = "registers" CONF_RETRIES = "retries" CONF_RETRY_ON_EMPTY = "retry_on_empty" CONF_PRECISION = "precision" @@ -69,8 +61,6 @@ CONF_HVAC_MODE_DRY = "state_dry" CONF_HVAC_MODE_FAN_ONLY = "state_fan_only" CONF_WRITE_REGISTERS = "write_registers" CONF_VERIFY = "verify" -CONF_VERIFY_REGISTER = "verify_register" -CONF_VERIFY_STATE = "verify_state" CONF_WRITE_TYPE = "write_type" CONF_ZERO_SUPPRESS = "zero_suppress" @@ -82,7 +72,7 @@ UDP = "udp" # service call attributes ATTR_ADDRESS = CONF_ADDRESS -ATTR_HUB = CONF_HUB +ATTR_HUB = "hub" ATTR_UNIT = "unit" ATTR_SLAVE = "slave" ATTR_VALUE = "value" diff --git a/tests/components/modbus/test_init.py b/tests/components/modbus/test_init.py index d9d3b035c94..35c01ec478b 100644 --- a/tests/components/modbus/test_init.py +++ b/tests/components/modbus/test_init.py @@ -929,3 +929,20 @@ async def test_integration_reload_failed( assert "Modbus reloading" in caplog.text assert "connect failed, retry in pymodbus" in caplog.text + + +@pytest.mark.parametrize("do_config", [{}]) +async def test_integration_setup_failed( + hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_modbus +) -> None: + """Run test for integration setup on reload.""" + with mock.patch.object( + hass_config, + "YAML_CONFIG_FILE", + get_fixture_path("configuration.yaml", "modbus"), + ): + hass.data[DOMAIN][TEST_MODBUS_NAME].async_setup = mock.AsyncMock( + return_value=False + ) + await hass.services.async_call(DOMAIN, SERVICE_RELOAD, blocking=True) + await hass.async_block_till_done() diff --git a/tests/components/modbus/test_sensor.py b/tests/components/modbus/test_sensor.py index 48a081ef637..06b0b68a746 100644 --- a/tests/components/modbus/test_sensor.py +++ b/tests/components/modbus/test_sensor.py @@ -47,6 +47,8 @@ from homeassistant.setup import async_setup_component from .conftest import TEST_ENTITY_NAME, ReadResult, do_next_cycle +from tests.common import mock_restore_cache_with_extra_data + ENTITY_ID = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}".replace(" ", "_") SLAVE_UNIQUE_ID = "ground_floor_sensor" @@ -906,23 +908,27 @@ async def test_wrap_sensor(hass: HomeAssistant, mock_do_cycle, expected) -> None assert hass.states.get(ENTITY_ID).state == expected -@pytest.mark.parametrize( - "mock_test_state", - [(State(ENTITY_ID, "unknown"), State(f"{ENTITY_ID}_1", "119"))], - indirect=True, -) +@pytest.fixture(name="mock_restore") +async def mock_restore(hass): + """Mock restore cache.""" + mock_restore_cache_with_extra_data( + hass, + ( + ( + State(ENTITY_ID, "121"), + {"native_value": "121", "native_unit_of_measurement": "kg"}, + ), + ( + State(ENTITY_ID + "_1", "119"), + {"native_value": "119", "native_unit_of_measurement": "kg"}, + ), + ), + ) + + @pytest.mark.parametrize( "do_config", [ - { - CONF_SENSORS: [ - { - CONF_NAME: TEST_ENTITY_NAME, - CONF_ADDRESS: 51, - CONF_SCAN_INTERVAL: 0, - } - ] - }, { CONF_SENSORS: [ { @@ -936,10 +942,13 @@ async def test_wrap_sensor(hass: HomeAssistant, mock_do_cycle, expected) -> None ], ) async def test_restore_state_sensor( - hass: HomeAssistant, mock_test_state, mock_modbus + hass: HomeAssistant, mock_restore, mock_modbus ) -> None: """Run test for sensor restore state.""" - assert hass.states.get(ENTITY_ID).state == mock_test_state[0].state + state = hass.states.get(ENTITY_ID).state + state2 = hass.states.get(ENTITY_ID + "_1").state + assert state + assert state2 @pytest.mark.parametrize(