From 965bb2c8df2c5cb4d2984b535e3839e4342a1ca2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 16 Oct 2020 06:31:16 -0500 Subject: [PATCH] Update nest to use async_add_executor_job (#41926) --- homeassistant/components/nest/__init__.py | 2 +- homeassistant/components/nest/binary_sensor.py | 2 +- homeassistant/components/nest/camera.py | 4 +++- homeassistant/components/nest/climate.py | 2 +- homeassistant/components/nest/config_flow.py | 4 ++-- homeassistant/components/nest/local_auth.py | 2 +- homeassistant/components/nest/sensor.py | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/nest/__init__.py b/homeassistant/components/nest/__init__.py index 185bf7c78ef5..84390a1a4c33 100644 --- a/homeassistant/components/nest/__init__.py +++ b/homeassistant/components/nest/__init__.py @@ -149,7 +149,7 @@ async def async_setup_entry(hass, entry): _LOGGER.debug("proceeding with setup") conf = hass.data.get(DATA_NEST_CONFIG, {}) hass.data[DATA_NEST] = NestDevice(hass, conf, nest) - if not await hass.async_add_job(hass.data[DATA_NEST].initialize): + if not await hass.async_add_executor_job(hass.data[DATA_NEST].initialize): return False for component in "climate", "camera", "sensor", "binary_sensor": diff --git a/homeassistant/components/nest/binary_sensor.py b/homeassistant/components/nest/binary_sensor.py index 0e9198a0220d..56d4ac31b787 100644 --- a/homeassistant/components/nest/binary_sensor.py +++ b/homeassistant/components/nest/binary_sensor.py @@ -117,7 +117,7 @@ async def async_setup_entry(hass, entry, async_add_entities): return sensors - async_add_entities(await hass.async_add_job(get_binary_sensors), True) + async_add_entities(await hass.async_add_executor_job(get_binary_sensors), True) class NestBinarySensor(NestSensorDevice, BinarySensorEntity): diff --git a/homeassistant/components/nest/camera.py b/homeassistant/components/nest/camera.py index caa78a56a117..28188d11e2f3 100644 --- a/homeassistant/components/nest/camera.py +++ b/homeassistant/components/nest/camera.py @@ -24,7 +24,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None): async def async_setup_entry(hass, entry, async_add_entities): """Set up a Nest sensor based on a config entry.""" - camera_devices = await hass.async_add_job(hass.data[nest.DATA_NEST].cameras) + camera_devices = await hass.async_add_executor_job( + hass.data[nest.DATA_NEST].cameras + ) cameras = [NestCamera(structure, device) for structure, device in camera_devices] async_add_entities(cameras, True) diff --git a/homeassistant/components/nest/climate.py b/homeassistant/components/nest/climate.py index 9a84010a3bc8..7fdc1f7ac121 100644 --- a/homeassistant/components/nest/climate.py +++ b/homeassistant/components/nest/climate.py @@ -78,7 +78,7 @@ async def async_setup_entry(hass, entry, async_add_entities): """Set up the Nest climate device based on a config entry.""" temp_unit = hass.config.units.temperature_unit - thermostats = await hass.async_add_job(hass.data[DATA_NEST].thermostats) + thermostats = await hass.async_add_executor_job(hass.data[DATA_NEST].thermostats) all_devices = [ NestThermostat(structure, device, temp_unit) diff --git a/homeassistant/components/nest/config_flow.py b/homeassistant/components/nest/config_flow.py index df903b119816..87612f300640 100644 --- a/homeassistant/components/nest/config_flow.py +++ b/homeassistant/components/nest/config_flow.py @@ -136,12 +136,12 @@ class NestFlowHandler(config_entries.ConfigFlow): config_path = info["nest_conf_path"] - if not await self.hass.async_add_job(os.path.isfile, config_path): + if not await self.hass.async_add_executor_job(os.path.isfile, config_path): self.flow_impl = DOMAIN return await self.async_step_link() flow = self.hass.data[DATA_FLOW_IMPL][DOMAIN] - tokens = await self.hass.async_add_job(load_json, config_path) + tokens = await self.hass.async_add_executor_job(load_json, config_path) return self._entry_from_tokens( "Nest (import from configuration.yaml)", flow, tokens diff --git a/homeassistant/components/nest/local_auth.py b/homeassistant/components/nest/local_auth.py index df03c0543986..f54da8039ffe 100644 --- a/homeassistant/components/nest/local_auth.py +++ b/homeassistant/components/nest/local_auth.py @@ -40,7 +40,7 @@ async def resolve_auth_code(hass, client_id, client_secret, code): auth.pin = code try: - await hass.async_add_job(auth.login) + await hass.async_add_executor_job(auth.login) return await result except AuthorizationError as err: if err.response.status_code == HTTP_UNAUTHORIZED: diff --git a/homeassistant/components/nest/sensor.py b/homeassistant/components/nest/sensor.py index 6844269400a3..8c4418e7536d 100644 --- a/homeassistant/components/nest/sensor.py +++ b/homeassistant/components/nest/sensor.py @@ -144,7 +144,7 @@ async def async_setup_entry(hass, entry, async_add_entities): return all_sensors - async_add_entities(await hass.async_add_job(get_sensors), True) + async_add_entities(await hass.async_add_executor_job(get_sensors), True) class NestBasicSensor(NestSensorDevice):