Sleepiq single sleeper crash (#24941)

* Update sleepyq to 0.7

Fixes crash when working with a single sleeper.

* sleepiq: Handle null side definitions

These happen if no sleeper is defined for a side of the bed. Don't
create sensors for null sides; they'll crash every time we try to use
them.

* sleepiq: Fix urls mocked to match sleepyq 0.7

* sleepi: Fix test_sensor.TestSleepIQSensorSetup

Sleepyq 0.7 throws on empty strings, so we have to specify them.

* sleepiq: Test for ValueError thrown by sleepyq 0.7

* sleepiq: Drop no longer used HTTPError import

* sleepiq: Add tests for single sleeper case

* sleepiq: Shorten comments to not overflow line length

* sleepiq: Use formatted string literals for adding suffixes to test files

* sleepiq: Use str.format() for test suffixing
This commit is contained in:
David Winn authored and Pascal Vizeli committed 2019-07-07 08:40:02 +02:00
1 parent adbec5bffc
commit 628e12c944
11 files changed
+103 -18

No files matched your search

+1 -2
View File
@@ -1,7 +1,6 @@
"""Support for SleepIQ from SleepNumber."""
import logging
from datetime import timedelta
from requests.exceptions import HTTPError
import voluptuous as vol
@@ -53,7 +52,7 @@ def setup(hass, config):
try:
DATA = SleepIQData(client)
DATA.update()
except HTTPError:
except ValueError:
message = """
SleepIQ failed to login, double check your username and password"
"""
@@ -12,9 +12,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
data.update()
dev = list()
for bed_id, _ in data.beds.items():
for bed_id, bed in data.beds.items():
for side in sleepiq.SIDES:
dev.append(IsInBedBinarySensor(data, bed_id, side))
if getattr(bed, side) is not None:
dev.append(IsInBedBinarySensor(data, bed_id, side))
add_entities(dev)
@@ -3,7 +3,7 @@
"name": "Sleepiq",
"documentation": "https://www.home-assistant.io/components/sleepiq",
"requirements": [
"sleepyq==0.6"
"sleepyq==0.7"
],
"dependencies": [],
"codeowners": []
+3 -2
View File
@@ -13,9 +13,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
data.update()
dev = list()
for bed_id, _ in data.beds.items():
for bed_id, bed in data.beds.items():
for side in sleepiq.SIDES:
dev.append(SleepNumberSensor(data, bed_id, side))
if getattr(bed, side) is not None:
dev.append(SleepNumberSensor(data, bed_id, side))
add_entities(dev)