Fix Nest doing I/O inside event loop (#4855)

This commit is contained in:
Paulus Schoutsen 2016-12-11 17:34:26 -08:00
parent b857d5dad0
commit 2402897f47

View File

@ -128,13 +128,20 @@ class NestSensor(Entity):
# device specific # device specific
self._location = self.device.where self._location = self.device.where
self._name = self.device.name_long self._name = "{} {}".format(self.device.name_long,
self.variable.replace("_", " "))
self._state = None self._state = None
self._unit = None
@property @property
def name(self): def name(self):
"""Return the name of the nest, if any.""" """Return the name of the nest, if any."""
return "{} {}".format(self._name, self.variable.replace("_", " ")) return self._name
@property
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit
class NestBasicSensor(NestSensor): class NestBasicSensor(NestSensor):
@ -145,13 +152,10 @@ class NestBasicSensor(NestSensor):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@property
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return SENSOR_UNITS.get(self.variable, None)
def update(self): def update(self):
"""Retrieve latest state.""" """Retrieve latest state."""
self._unit = SENSOR_UNITS.get(self.variable, None)
if self.variable == 'operation_mode': if self.variable == 'operation_mode':
self._state = getattr(self.device, "mode") self._state = getattr(self.device, "mode")
else: else:
@ -161,14 +165,6 @@ class NestBasicSensor(NestSensor):
class NestTempSensor(NestSensor): class NestTempSensor(NestSensor):
"""Representation of a Nest Temperature sensor.""" """Representation of a Nest Temperature sensor."""
@property
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
if self.device.temperature_scale == 'C':
return TEMP_CELSIUS
else:
return TEMP_FAHRENHEIT
@property @property
def state(self): def state(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
@ -176,6 +172,11 @@ class NestTempSensor(NestSensor):
def update(self): def update(self):
"""Retrieve latest state.""" """Retrieve latest state."""
if self.device.temperature_scale == 'C':
self._unit = TEMP_CELSIUS
else:
self._unit = TEMP_FAHRENHEIT
temp = getattr(self.device, self.variable) temp = getattr(self.device, self.variable)
if temp is None: if temp is None:
self._state = None self._state = None