8000 Fix Nest doing I/O inside event loop by balloob · Pull Request #4855 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix Nest doing I/O inside event loop #4855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions homeassistant/components/sensor/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,20 @@ def __init__(self, structure, device, variable):

# device specific
self._location = self.device.where
self._name = self.device.name_long
self._name = "{} {}".format(self.device.name_long,
self.variable.replace("_", " "))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line introduced this error when you have Cameras:

16-12-16 11:16:52 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform nest
Traceback (most recent call last):
  File "/Users/technicalpickles/src/picklehome/vendor/home-assistant/homeassistant/helpers/entity_component.py", line 150, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/futures.py", line 361, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
    future.result()
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/technicalpickles/src/picklehome/vendor/home-assistant/homeassistant/components/binary_sensor/nest.py", line 98, in setup_platform
    activity_zone)]
  File "/Users/technicalpickles/src/picklehome/vendor/home-assistant/homeassistant/components/binary_sensor/nest.py", line 121, in __init__
    super(NestActivityZoneSensor, self).__init__(structure, device, None)
  File "/Users/technicalpickles/src/picklehome/vendor/home-assistant/homeassistant/components/sensor/nest.py", line 136, in __init__
    self.variable.replace("_", " "))
AttributeError: 'NoneType' object has no attribute 'replace'

It looks like it's my bad use of inheritence, where an NestActivityZoneSensor in the binary sensor passes in variable of None, since it's doing it's own thing.

I'll followup with a PR to fix.

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):
Expand All @@ -145,13 +152,10 @@ def state(self):
"""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:
Expand All @@ -161,21 +165,18 @@ def update(self):
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."""
return self._state

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
Expand Down
0