Qwikswitch Entity Register (#13791)

* Entity Register

* feedback
This commit is contained in:
Johann Kellerman 2018-04-10 01:24:06 +02:00 committed by Martin Hjelmare
parent ae4e792651
commit 7595401dcb
3 changed files with 13 additions and 3 deletions

View File

@ -64,6 +64,12 @@ class QSEntity(Entity):
"""QS sensors gets packets in update_packet."""
return False
@property
def unique_id(self):
"""Return a unique identifier for this sensor."""
return "qs{}".format(self.qsid)
@callback
def update_packet(self, packet):
"""Receive update packet from QSUSB. Match dispather_send signature."""
self.async_schedule_update_ha_state()

View File

@ -7,6 +7,7 @@ https://home-assistant.io/components/sensor.qwikswitch/
import logging
from homeassistant.components.qwikswitch import DOMAIN as QWIKSWITCH, QSEntity
from homeassistant.core import callback
DEPENDENCIES = [QWIKSWITCH]
@ -41,6 +42,7 @@ class QSSensor(QSEntity):
if isinstance(self.unit, type):
self.unit = "{}:{}".format(self.sensor_type, self.channel)
@callback
def update_packet(self, packet):
"""Receive update packet from QSUSB."""
val = self._decode(packet.get('data'), channel=self.channel)
@ -55,6 +57,11 @@ class QSSensor(QSEntity):
"""Return the value of the sensor."""
return str(self._val)
@property
def unique_id(self):
"""Return a unique identifier for this sensor."""
return "qs{}:{}".format(self.qsid, self.channel)
@property
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""

View File

@ -1,5 +1,4 @@
"""Test qwikswitch sensors."""
import asyncio
import logging
import pytest
@ -29,7 +28,6 @@ class AiohttpClientMockResponseList(list):
async def wait_till_empty(self, hass):
"""Wait until empty."""
while self:
await asyncio.sleep(1)
await hass.async_block_till_done()
await hass.async_block_till_done()
@ -54,7 +52,6 @@ def aioclient_mock():
yield mock_session
# @asyncio.coroutine
async def test_sensor_device(hass, aioclient_mock):
"""Test a sensor device."""
config = {