Switch rfxtrx to integration level config (#37742)
* Switch to integration level config * Switch to per device config rather than per entity type * All roller shutters should be added as covers (there are non lighting types) * Fixup tests that used invalid packets for platforms * Avoid variable re-use * Allow control events on sensors too That way we get signal level sensors for these too * Lint correction * Don't filter sensors from config Disable sensors from GUI if the entities are not wanted * Correct usage of ATTR_ instead of CONF_ * Make sure the logging when a new entity is added includes the event
This commit is contained in:
1 parent
16a947aa5f
commit
53844488d8
13 files changed
+430
-900
No files matched your search
@@ -17,46 +17,46 @@ async def test_default_config(hass, rfxtrx):
|
||||
|
||||
async def test_one_sensor(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
await async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
"rfxtrx",
|
||||
{
|
||||
"sensor": {
|
||||
"platform": "rfxtrx",
|
||||
"devices": {
|
||||
"0a52080705020095220269": {
|
||||
"name": "Test",
|
||||
"data_type": "Temperature",
|
||||
}
|
||||
},
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"dummy": True,
|
||||
"devices": {"0a52080705020095220269": {}},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.test_temperature")
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02_temperature")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
assert state.attributes.get("friendly_name") == "Test Temperature"
|
||||
assert (
|
||||
state.attributes.get("friendly_name")
|
||||
== "WT260,WT260H,WT440H,WT450,WT450H 05:02 Temperature"
|
||||
)
|
||||
assert state.attributes.get("unit_of_measurement") == TEMP_CELSIUS
|
||||
|
||||
|
||||
async def test_one_sensor_no_datatype(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
await async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
"rfxtrx",
|
||||
{
|
||||
"sensor": {
|
||||
"platform": "rfxtrx",
|
||||
"devices": {"0a52080705020095220269": {"name": "Test"}},
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"dummy": True,
|
||||
"devices": {"0a52080705020095220269": {}},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
base_id = "sensor.test"
|
||||
base_name = "Test"
|
||||
base_id = "sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02"
|
||||
base_name = "WT260,WT260H,WT440H,WT450,WT450H 05:02"
|
||||
|
||||
state = hass.states.get(f"{base_id}_temperature")
|
||||
assert state
|
||||
@@ -91,58 +91,63 @@ async def test_one_sensor_no_datatype(hass, rfxtrx):
|
||||
|
||||
async def test_several_sensors(hass, rfxtrx):
|
||||
"""Test with 3 sensors."""
|
||||
await async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
"rfxtrx",
|
||||
{
|
||||
"sensor": {
|
||||
"platform": "rfxtrx",
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"dummy": True,
|
||||
"devices": {
|
||||
"0a52080705020095220269": {
|
||||
"name": "Test",
|
||||
"data_type": "Temperature",
|
||||
},
|
||||
"0a520802060100ff0e0269": {
|
||||
"name": "Bath",
|
||||
"data_type": ["Temperature", "Humidity"],
|
||||
},
|
||||
"0a52080705020095220269": {},
|
||||
"0a520802060100ff0e0269": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.test_temperature")
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02_temperature")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
assert state.attributes.get("friendly_name") == "Test Temperature"
|
||||
assert (
|
||||
state.attributes.get("friendly_name")
|
||||
== "WT260,WT260H,WT440H,WT450,WT450H 05:02 Temperature"
|
||||
)
|
||||
assert state.attributes.get("unit_of_measurement") == TEMP_CELSIUS
|
||||
|
||||
state = hass.states.get("sensor.bath_temperature")
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_temperature")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
assert state.attributes.get("friendly_name") == "Bath Temperature"
|
||||
assert (
|
||||
state.attributes.get("friendly_name")
|
||||
== "WT260,WT260H,WT440H,WT450,WT450H 06:01 Temperature"
|
||||
)
|
||||
assert state.attributes.get("unit_of_measurement") == TEMP_CELSIUS
|
||||
|
||||
state = hass.states.get("sensor.bath_humidity")
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_humidity")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
assert state.attributes.get("friendly_name") == "Bath Humidity"
|
||||
assert (
|
||||
state.attributes.get("friendly_name")
|
||||
== "WT260,WT260H,WT440H,WT450,WT450H 06:01 Humidity"
|
||||
)
|
||||
assert state.attributes.get("unit_of_measurement") == UNIT_PERCENTAGE
|
||||
|
||||
|
||||
async def test_discover_sensor(hass, rfxtrx):
|
||||
"""Test with discovery of sensor."""
|
||||
await async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
{"sensor": {"platform": "rfxtrx", "automatic_add": True, "devices": {}}},
|
||||
"rfxtrx",
|
||||
{"rfxtrx": {"device": "abcd", "dummy": True, "automatic_add": True}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# 1
|
||||
await _signal_event(hass, "0a520801070100b81b0279")
|
||||
base_id = "sensor.0a520801070100b81b0279"
|
||||
base_id = "sensor.wt260_wt260h_wt440h_wt450_wt450h_07_01"
|
||||
|
||||
state = hass.states.get(f"{base_id}_humidity")
|
||||
assert state
|
||||
@@ -171,7 +176,7 @@ async def test_discover_sensor(hass, rfxtrx):
|
||||
|
||||
# 2
|
||||
await _signal_event(hass, "0a52080405020095240279")
|
||||
base_id = "sensor.0a52080405020095240279"
|
||||
base_id = "sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02"
|
||||
state = hass.states.get(f"{base_id}_humidity")
|
||||
|
||||
assert state
|
||||
@@ -200,7 +205,7 @@ async def test_discover_sensor(hass, rfxtrx):
|
||||
|
||||
# 1 Update
|
||||
await _signal_event(hass, "0a52085e070100b31b0279")
|
||||
base_id = "sensor.0a520801070100b81b0279"
|
||||
base_id = "sensor.wt260_wt260h_wt440h_wt450_wt450h_07_01"
|
||||
|
||||
state = hass.states.get(f"{base_id}_humidity")
|
||||
assert state
|
||||
@@ -230,75 +235,47 @@ async def test_discover_sensor(hass, rfxtrx):
|
||||
assert len(hass.states.async_all()) == 10
|
||||
|
||||
|
||||
async def test_discover_sensor_noautoadd(hass, rfxtrx):
|
||||
"""Test with discover of sensor when auto add is False."""
|
||||
await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
{"sensor": {"platform": "rfxtrx", "automatic_add": False, "devices": {}}},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await _signal_event(hass, "0a520801070100b81b0279")
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
await _signal_event(hass, "0a52080405020095240279")
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
await _signal_event(hass, "0a52085e070100b31b0279")
|
||||
assert len(hass.states.async_all()) == 0
|
||||
|
||||
|
||||
async def test_update_of_sensors(hass, rfxtrx):
|
||||
"""Test with 3 sensors."""
|
||||
await async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"sensor",
|
||||
"rfxtrx",
|
||||
{
|
||||
"sensor": {
|
||||
"platform": "rfxtrx",
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"dummy": True,
|
||||
"devices": {
|
||||
"0a52080705020095220269": {
|
||||
"name": "Test",
|
||||
"data_type": "Temperature",
|
||||
},
|
||||
"0a520802060100ff0e0269": {
|
||||
"name": "Bath",
|
||||
"data_type": ["Temperature", "Humidity"],
|
||||
},
|
||||
"0a52080705020095220269": {},
|
||||
"0a520802060100ff0e0269": {},
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.test_temperature")
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02_temperature")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
|
||||
state = hass.states.get("sensor.bath_temperature")
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_temperature")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
|
||||
state = hass.states.get("sensor.bath_humidity")
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_humidity")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
|
||||
assert len(hass.states.async_all()) == 3
|
||||
|
||||
await _signal_event(hass, "0a520802060101ff0f0269")
|
||||
await _signal_event(hass, "0a52080705020085220269")
|
||||
|
||||
state = hass.states.get("sensor.test_temperature")
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02_temperature")
|
||||
assert state
|
||||
assert state.state == "13.3"
|
||||
|
||||
state = hass.states.get("sensor.bath_temperature")
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_temperature")
|
||||
assert state
|
||||
assert state.state == "51.1"
|
||||
|
||||
state = hass.states.get("sensor.bath_humidity")
|
||||
state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_humidity")
|
||||
assert state
|
||||
assert state.state == "15"
|
||||
|
||||
assert len(hass.states.async_all()) == 3
|
||||
Reference in new issue
Block a user