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

pull/4822/head^2
Paulus Schoutsen 2016-12-11 17:34:26 -08:00 committed by GitHub
parent f4b5c439a1
commit df98d5b3c1
1 changed files with 16 additions and 15 deletions

View File

@ -128,13 +128,20 @@ class NestSensor(Entity):
# device specific
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._unit = None
@property
def name(self):
"""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):
@ -145,13 +152,10 @@ class NestBasicSensor(NestSensor):
"""Return the state of the sensor."""
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):
"""Retrieve latest state."""
self._unit = SENSOR_UNITS.get(self.variable, None)
if self.variable == 'operation_mode':
self._state = getattr(self.device, "mode")
else:
@ -161,14 +165,6 @@ class NestBasicSensor(NestSensor):
class NestTempSensor(NestSensor):
"""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
def state(self):
"""Return the state of the sensor."""
@ -176,6 +172,11 @@ class NestTempSensor(NestSensor):
def update(self):
"""Retrieve latest state."""
if self.device.temperature_scale == 'C':
self._unit = TEMP_CELSIUS
else:
self._unit = TEMP_FAHRENHEIT
temp = getattr(self.device, self.variable)
if temp is None:
self._state = None