Update nest library and switch events to async (#43583)

This commit is contained in:
Allen Porter 2020-11-24 07:53:50 -08:00 committed by GitHub
parent 7214d6517a
commit 3dd14e05e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 16 deletions

View File

@ -5,7 +5,7 @@ from datetime import datetime, timedelta
import logging import logging
import threading import threading
from google_nest_sdm.event import EventCallback, EventMessage from google_nest_sdm.event import AsyncEventCallback, EventMessage
from google_nest_sdm.exceptions import GoogleNestException from google_nest_sdm.exceptions import GoogleNestException
from google_nest_sdm.google_nest_subscriber import GoogleNestSubscriber from google_nest_sdm.google_nest_subscriber import GoogleNestSubscriber
from nest import Nest from nest import Nest
@ -160,14 +160,14 @@ async def async_setup(hass: HomeAssistant, config: dict):
return True return True
class SignalUpdateCallback(EventCallback): class SignalUpdateCallback(AsyncEventCallback):
"""An EventCallback invoked when new events arrive from subscriber.""" """An EventCallback invoked when new events arrive from subscriber."""
def __init__(self, hass: HomeAssistant): def __init__(self, hass: HomeAssistant):
"""Initialize EventCallback.""" """Initialize EventCallback."""
self._hass = hass self._hass = hass
def handle_event(self, event_message: EventMessage): async def async_handle_event(self, event_message: EventMessage):
"""Process an incoming EventMessage.""" """Process an incoming EventMessage."""
_LOGGER.debug("Update %s @ %s", event_message.event_id, event_message.timestamp) _LOGGER.debug("Update %s @ %s", event_message.event_id, event_message.timestamp)
traits = event_message.resource_update_traits traits = event_message.resource_update_traits

View File

@ -6,7 +6,7 @@
"documentation": "https://www.home-assistant.io/integrations/nest", "documentation": "https://www.home-assistant.io/integrations/nest",
"requirements": [ "requirements": [
"python-nest==4.1.0", "python-nest==4.1.0",
"google-nest-sdm==0.1.15" "google-nest-sdm==0.2.0"
], ],
"codeowners": [ "codeowners": [
"@awarecan", "@awarecan",

View File

@ -684,7 +684,7 @@ google-cloud-pubsub==2.1.0
google-cloud-texttospeech==0.4.0 google-cloud-texttospeech==0.4.0
# homeassistant.components.nest # homeassistant.components.nest
google-nest-sdm==0.1.15 google-nest-sdm==0.2.0
# homeassistant.components.google_travel_time # homeassistant.components.google_travel_time
googlemaps==2.5.1 googlemaps==2.5.1

View File

@ -355,7 +355,7 @@ google-api-python-client==1.6.4
google-cloud-pubsub==2.1.0 google-cloud-pubsub==2.1.0
# homeassistant.components.nest # homeassistant.components.nest
google-nest-sdm==0.1.15 google-nest-sdm==0.2.0
# homeassistant.components.gree # homeassistant.components.gree
greeclimate==0.10.3 greeclimate==0.10.3

View File

@ -417,7 +417,7 @@ async def test_thermostat_set_hvac_mode(hass, auth):
}, },
auth=None, auth=None,
) )
subscriber.receive_event(event) await subscriber.async_receive_event(event)
await hass.async_block_till_done() # Process dispatch/update signal await hass.async_block_till_done() # Process dispatch/update signal
thermostat = hass.states.get("climate.my_thermostat") thermostat = hass.states.get("climate.my_thermostat")
@ -441,7 +441,7 @@ async def test_thermostat_set_hvac_mode(hass, auth):
}, },
auth=None, auth=None,
) )
subscriber.receive_event(event) await subscriber.async_receive_event(event)
await hass.async_block_till_done() # Process dispatch/update signal await hass.async_block_till_done() # Process dispatch/update signal
thermostat = hass.states.get("climate.my_thermostat") thermostat = hass.states.get("climate.my_thermostat")
@ -514,7 +514,7 @@ async def test_thermostat_set_eco_preset(hass, auth):
}, },
auth=auth, auth=auth,
) )
subscriber.receive_event(event) await subscriber.async_receive_event(event)
await hass.async_block_till_done() # Process dispatch/update signal await hass.async_block_till_done() # Process dispatch/update signal
thermostat = hass.states.get("climate.my_thermostat") thermostat = hass.states.get("climate.my_thermostat")
@ -834,7 +834,7 @@ async def test_thermostat_target_temp(hass, auth):
}, },
auth=None, auth=None,
) )
subscriber.receive_event(event) await subscriber.async_receive_event(event)
await hass.async_block_till_done() # Process dispatch/update signal await hass.async_block_till_done() # Process dispatch/update signal
thermostat = hass.states.get("climate.my_thermostat") thermostat = hass.states.get("climate.my_thermostat")

View File

@ -3,7 +3,7 @@
import time import time
from google_nest_sdm.device_manager import DeviceManager from google_nest_sdm.device_manager import DeviceManager
from google_nest_sdm.event import EventCallback, EventMessage from google_nest_sdm.event import AsyncEventCallback, EventMessage
from google_nest_sdm.google_nest_subscriber import GoogleNestSubscriber from google_nest_sdm.google_nest_subscriber import GoogleNestSubscriber
from homeassistant.components.nest import DOMAIN from homeassistant.components.nest import DOMAIN
@ -61,7 +61,7 @@ class FakeSubscriber(GoogleNestSubscriber):
self._device_manager = device_manager self._device_manager = device_manager
self._callback = None self._callback = None
def set_update_callback(self, callback: EventCallback): def set_update_callback(self, callback: AsyncEventCallback):
"""Capture the callback set by Home Assistant.""" """Capture the callback set by Home Assistant."""
self._callback = callback self._callback = callback
@ -77,11 +77,11 @@ class FakeSubscriber(GoogleNestSubscriber):
"""No-op to stop the subscriber.""" """No-op to stop the subscriber."""
return None return None
def receive_event(self, event_message: EventMessage): async def async_receive_event(self, event_message: EventMessage):
"""Simulate a received pubsub message, invoked by tests.""" """Simulate a received pubsub message, invoked by tests."""
# Update device state, then invoke HomeAssistant to refresh # Update device state, then invoke HomeAssistant to refresh
self._device_manager.handle_event(event_message) await self._device_manager.async_handle_event(event_message)
self._callback.handle_event(event_message) await self._callback.async_handle_event(event_message)
async def async_setup_sdm_platform(hass, platform, devices={}, structures={}): async def async_setup_sdm_platform(hass, platform, devices={}, structures={}):

View File

@ -164,7 +164,7 @@ async def test_event_updates_sensor(hass):
}, },
auth=None, auth=None,
) )
subscriber.receive_event(event) await subscriber.async_receive_event(event)
await hass.async_block_till_done() # Process dispatch/update signal await hass.async_block_till_done() # Process dispatch/update signal
temperature = hass.states.get("sensor.my_sensor_temperature") temperature = hass.states.get("sensor.my_sensor_temperature")