Skip to content
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

Rfxtrx sensor #2563

Merged
merged 3 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Add test for rfxtrx fire event in sensor
  • Loading branch information
Daniel authored and Daniel committed Jul 19, 2016
commit 6bd33548b1827c107ad50227b4572d014ad8e084
5 changes: 2 additions & 3 deletions homeassistant/components/sensor/rfxtrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify
from homeassistant.components.rfxtrx import (
ATTR_AUTOMATIC_ADD, ATTR_NAME, ATTR_FIREEVENT, ATTR_STATE,
ATTR_AUTOMATIC_ADD, ATTR_NAME, ATTR_FIREEVENT,
CONF_DEVICES, ATTR_DATA_TYPE, DATA_TYPES, ATTR_ENTITY_ID)

DEPENDENCIES = ['rfxtrx']
Expand Down Expand Up @@ -47,7 +47,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
data_types = [data_type]
break
for _data_type in data_types:
new_sensor = RfxtrxSensor(event, entity_info[ATTR_NAME],
new_sensor = RfxtrxSensor(None, entity_info[ATTR_NAME],
_data_type, entity_info[ATTR_FIREEVENT])
sensors.append(new_sensor)
sub_sensors[_data_type] = new_sensor
Expand All @@ -73,7 +73,6 @@ def sensor_update(event):
"signal_received", {
ATTR_ENTITY_ID:
sensors[key].entity_id,
ATTR_STATE: event.values[sensor.data_type],
}
)

Expand Down
34 changes: 34 additions & 0 deletions tests/components/test_rfxtrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,37 @@ def record_event(event):
self.assertEqual(1, len(calls))
self.assertEqual(calls[0].data,
{'entity_id': 'switch.test', 'state': 'on'})

def test_fire_event_sensor(self):
"""Test fire event."""
self.assertTrue(_setup_component(self.hass, 'rfxtrx', {
'rfxtrx': {
'device': '/dev/serial/by-id/usb' +
'-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0',
'dummy': True}
}))
self.assertTrue(_setup_component(self.hass, 'sensor', {
'sensor': {'platform': 'rfxtrx',
'automatic_add': True,
'devices':
{'0a520802060100ff0e0269': {
'name': 'Test',
rfxtrx.ATTR_FIREEVENT: True}
}}}))

calls = []

def record_event(event):
"""Add recorded event to set."""
calls.append(event)

self.hass.bus.listen("signal_received", record_event)
event = rfxtrx.get_rfx_object('0a520802060101ff0f0269')
event.data = bytearray(b'\nR\x08\x01\x07\x01\x00\xb8\x1b\x02y')
rfxtrx.RECEIVED_EVT_SUBSCRIBERS[0](event)

self.hass.pool.block_till_done()
self.assertEqual(1, len(rfxtrx.RFX_DEVICES))
self.assertEqual(1, len(calls))
self.assertEqual(calls[0].data,
{'entity_id': 'sensor.test'})