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 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.google_nest_subscriber import GoogleNestSubscriber
from nest import Nest
@ -160,14 +160,14 @@ async def async_setup(hass: HomeAssistant, config: dict):
return True
class SignalUpdateCallback(EventCallback):
class SignalUpdateCallback(AsyncEventCallback):
"""An EventCallback invoked when new events arrive from subscriber."""
def __init__(self, hass: HomeAssistant):
"""Initialize EventCallback."""
self._hass = hass
def handle_event(self, event_message: EventMessage):
async def async_handle_event(self, event_message: EventMessage):
"""Process an incoming EventMessage."""
_LOGGER.debug("Update %s @ %s", event_message.event_id, event_message.timestamp)
traits = event_message.resource_update_traits

View file

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

View file

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

View file

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

View file

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

View file

@ -3,7 +3,7 @@
import time
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 homeassistant.components.nest import DOMAIN
@ -61,7 +61,7 @@ class FakeSubscriber(GoogleNestSubscriber):
self._device_manager = device_manager
self._callback = None
def set_update_callback(self, callback: EventCallback):
def set_update_callback(self, callback: AsyncEventCallback):
"""Capture the callback set by Home Assistant."""
self._callback = callback
@ -77,11 +77,11 @@ class FakeSubscriber(GoogleNestSubscriber):
"""No-op to stop the subscriber."""
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."""
# Update device state, then invoke HomeAssistant to refresh
self._device_manager.handle_event(event_message)
self._callback.handle_event(event_message)
await self._device_manager.async_handle_event(event_message)
await self._callback.async_handle_event(event_message)
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,
)
subscriber.receive_event(event)
await subscriber.async_receive_event(event)
await hass.async_block_till_done() # Process dispatch/update signal
temperature = hass.states.get("sensor.my_sensor_temperature")