diff --git a/homeassistant/components/esphome/manager.py b/homeassistant/components/esphome/manager.py index 4d5de77b1e0..742ed266bf3 100644 --- a/homeassistant/components/esphome/manager.py +++ b/homeassistant/components/esphome/manager.py @@ -564,11 +564,11 @@ class ESPHomeManager: ) entry_data.loaded_platforms.add(Platform.ASSIST_SATELLITE) - cli.subscribe_states(entry_data.async_update_state) - cli.subscribe_service_calls(self.async_on_service_call) - cli.subscribe_home_assistant_states( - self.async_on_state_subscription, - self.async_on_state_request, + cli.subscribe_home_assistant_states_and_services( + on_state=entry_data.async_update_state, + on_service_call=self.async_on_service_call, + on_state_sub=self.async_on_state_subscription, + on_state_request=self.async_on_state_request, ) entry_data.async_save_to_store() diff --git a/homeassistant/components/esphome/manifest.json b/homeassistant/components/esphome/manifest.json index 6bf164aa9bc..fafeecc1304 100644 --- a/homeassistant/components/esphome/manifest.json +++ b/homeassistant/components/esphome/manifest.json @@ -17,7 +17,7 @@ "mqtt": ["esphome/discover/#"], "quality_scale": "platinum", "requirements": [ - "aioesphomeapi==37.2.2", + "aioesphomeapi==38.2.1", "esphome-dashboard-api==1.3.0", "bleak-esphome==3.1.0" ], diff --git a/requirements_all.txt b/requirements_all.txt index e5d8b95b89a..4cd27301bec 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -247,7 +247,7 @@ aioelectricitymaps==0.4.0 aioemonitor==1.0.5 # homeassistant.components.esphome -aioesphomeapi==37.2.2 +aioesphomeapi==38.2.1 # homeassistant.components.flo aioflo==2021.11.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index a7cac53c700..537ca44d85e 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -235,7 +235,7 @@ aioelectricitymaps==0.4.0 aioemonitor==1.0.5 # homeassistant.components.esphome -aioesphomeapi==37.2.2 +aioesphomeapi==38.2.1 # homeassistant.components.flo aioflo==2021.11.0 diff --git a/tests/components/esphome/conftest.py b/tests/components/esphome/conftest.py index 9de97bac3eb..35885722d8a 100644 --- a/tests/components/esphome/conftest.py +++ b/tests/components/esphome/conftest.py @@ -517,9 +517,27 @@ async def _mock_generic_device_entry( mock_client.list_entities_services = AsyncMock( return_value=mock_list_entities_services ) - mock_client.subscribe_states = _subscribe_states - mock_client.subscribe_service_calls = _subscribe_service_calls - mock_client.subscribe_home_assistant_states = _subscribe_home_assistant_states + + def _subscribe_home_assistant_states_and_services( + *, + on_state: Callable[[EntityState], None], + on_service_call: Callable[[HomeassistantServiceCall], None], + on_state_sub: Callable[[str, str | None], None], + on_state_request: Callable[[str, str | None], None], + ) -> None: + """Subscribe to states and service calls.""" + mock_device.set_state_callback(on_state) + mock_device.set_service_call_callback(on_service_call) + mock_device.set_home_assistant_state_subscription_callback( + on_state_sub, on_state_request + ) + # Set the initial states + for state in states: + on_state(state) + + mock_client.subscribe_home_assistant_states_and_services = ( + _subscribe_home_assistant_states_and_services + ) mock_client.subscribe_logs = _subscribe_logs try_connect_done = Event() diff --git a/tests/components/esphome/test_manager.py b/tests/components/esphome/test_manager.py index fec957a9560..c29dbad1d37 100644 --- a/tests/components/esphome/test_manager.py +++ b/tests/components/esphome/test_manager.py @@ -416,10 +416,12 @@ async def test_unique_id_updated_to_mac( entry.add_to_hass(hass) subscribe_done = hass.loop.create_future() - def async_subscribe_states(*args, **kwargs) -> None: + def async_subscribe_home_assistant_states_and_services(*args, **kwargs) -> None: subscribe_done.set_result(None) - mock_client.subscribe_states = async_subscribe_states + mock_client.subscribe_home_assistant_states_and_services = ( + async_subscribe_home_assistant_states_and_services + ) mock_client.device_info = AsyncMock( return_value=DeviceInfo( mac_address="1122334455aa", @@ -447,10 +449,12 @@ async def test_add_missing_bluetooth_mac_address( entry.add_to_hass(hass) subscribe_done = hass.loop.create_future() - def async_subscribe_states(*args, **kwargs) -> None: + def async_subscribe_home_assistant_states_and_services(*args, **kwargs) -> None: subscribe_done.set_result(None) - mock_client.subscribe_states = async_subscribe_states + mock_client.subscribe_home_assistant_states_and_services = ( + async_subscribe_home_assistant_states_and_services + ) mock_client.device_info = AsyncMock( return_value=DeviceInfo( mac_address="1122334455aa", @@ -587,10 +591,12 @@ async def test_name_updated_only_if_mac_matches( entry.add_to_hass(hass) subscribe_done = hass.loop.create_future() - def async_subscribe_states(*args, **kwargs) -> None: + def async_subscribe_home_assistant_states_and_services(*args, **kwargs) -> None: subscribe_done.set_result(None) - mock_client.subscribe_states = async_subscribe_states + mock_client.subscribe_home_assistant_states_and_services = ( + async_subscribe_home_assistant_states_and_services + ) mock_client.device_info = AsyncMock( return_value=DeviceInfo(mac_address="1122334455aa", name="new") ) @@ -622,10 +628,12 @@ async def test_name_updated_only_if_mac_was_unset( entry.add_to_hass(hass) subscribe_done = hass.loop.create_future() - def async_subscribe_states(*args, **kwargs) -> None: + def async_subscribe_home_assistant_states_and_services(*args, **kwargs) -> None: subscribe_done.set_result(None) - mock_client.subscribe_states = async_subscribe_states + mock_client.subscribe_home_assistant_states_and_services = ( + async_subscribe_home_assistant_states_and_services + ) mock_client.device_info = AsyncMock( return_value=DeviceInfo(mac_address="1122334455aa", name="new") )