Remove global variable from sleepiq (#33715)

* Remove global variable from sleepiq

* Remove global variable from sleepiq v2

* Create constant file

* Move back time constant

* Update homeassistant/components/sleepiq/__init__.py

Co-Authored-By: Quentame <polletquentin74@me.com>

Co-authored-by: Quentame <polletquentin74@me.com>
This commit is contained in:
springstanandQuentame authored and GitHub committed 2020-04-06 00:46:50 +02:00
1 parent 67c3a4c970
commit 2e6108365e
4 files changed
+35 -30

No files matched your search

+9 -8
View File
@@ -1,5 +1,6 @@
"""Support for SleepIQ sensors."""
from homeassistant.components import sleepiq
from . import SleepIQSensor
from .const import DOMAIN, SENSOR_TYPES, SIDES, SLEEP_NUMBER
ICON = "mdi:hotel"
@@ -9,27 +10,27 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if discovery_info is None:
return
data = sleepiq.DATA
data = hass.data[DOMAIN]
data.update()
dev = []
for bed_id, bed in data.beds.items():
for side in sleepiq.SIDES:
for side in SIDES:
if getattr(bed, side) is not None:
dev.append(SleepNumberSensor(data, bed_id, side))
add_entities(dev)
class SleepNumberSensor(sleepiq.SleepIQSensor):
class SleepNumberSensor(SleepIQSensor):
"""Implementation of a SleepIQ sensor."""
def __init__(self, sleepiq_data, bed_id, side):
"""Initialize the sensor."""
sleepiq.SleepIQSensor.__init__(self, sleepiq_data, bed_id, side)
SleepIQSensor.__init__(self, sleepiq_data, bed_id, side)
self._state = None
self.type = sleepiq.SLEEP_NUMBER
self._name = sleepiq.SENSOR_TYPES[self.type]
self.type = SLEEP_NUMBER
self._name = SENSOR_TYPES[self.type]
self.update()
@@ -45,5 +46,5 @@ class SleepNumberSensor(sleepiq.SleepIQSensor):
def update(self):
"""Get the latest data from SleepIQ and updates the states."""
sleepiq.SleepIQSensor.update(self)
SleepIQSensor.update(self)
self._state = self.side.sleep_number