Add current_humidity device_trigger for humidity component (#95435)
Add current_humidity device_trigger for humidity
This commit is contained in:
parent
0bfb81ecf3
commit
fe7857c8ec
2 changed files with 135 additions and 16 deletions
|
@ -64,12 +64,13 @@ async def test_get_triggers(
|
|||
STATE_ON,
|
||||
{
|
||||
const.ATTR_HUMIDITY: 23,
|
||||
const.ATTR_CURRENT_HUMIDITY: 48,
|
||||
ATTR_MODE: "home",
|
||||
const.ATTR_AVAILABLE_MODES: ["home", "away"],
|
||||
ATTR_SUPPORTED_FEATURES: 1,
|
||||
},
|
||||
)
|
||||
humidifier_trigger_types = ["target_humidity_changed"]
|
||||
humidifier_trigger_types = ["current_humidity_changed", "target_humidity_changed"]
|
||||
toggle_trigger_types = ["turned_on", "turned_off", "changed_states"]
|
||||
expected_triggers = [
|
||||
{
|
||||
|
@ -171,6 +172,7 @@ async def test_if_fires_on_state_change(
|
|||
STATE_ON,
|
||||
{
|
||||
const.ATTR_HUMIDITY: 23,
|
||||
const.ATTR_CURRENT_HUMIDITY: 35,
|
||||
ATTR_MODE: "home",
|
||||
const.ATTR_AVAILABLE_MODES: ["home", "away"],
|
||||
ATTR_SUPPORTED_FEATURES: 1,
|
||||
|
@ -225,6 +227,49 @@ async def test_if_fires_on_state_change(
|
|||
"data_template": {"some": "target_humidity_changed_above_for"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"trigger": {
|
||||
"platform": "device",
|
||||
"domain": DOMAIN,
|
||||
"device_id": "",
|
||||
"entity_id": entry.id,
|
||||
"type": "current_humidity_changed",
|
||||
"below": 30,
|
||||
},
|
||||
"action": {
|
||||
"service": "test.automation",
|
||||
"data_template": {"some": "current_humidity_changed_below"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"trigger": {
|
||||
"platform": "device",
|
||||
"domain": DOMAIN,
|
||||
"device_id": "",
|
||||
"entity_id": entry.id,
|
||||
"type": "current_humidity_changed",
|
||||
"above": 40,
|
||||
},
|
||||
"action": {
|
||||
"service": "test.automation",
|
||||
"data_template": {"some": "current_humidity_changed_above"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"trigger": {
|
||||
"platform": "device",
|
||||
"domain": DOMAIN,
|
||||
"device_id": "",
|
||||
"entity_id": entry.id,
|
||||
"type": "current_humidity_changed",
|
||||
"above": 40,
|
||||
"for": {"seconds": 5},
|
||||
},
|
||||
"action": {
|
||||
"service": "test.automation",
|
||||
"data_template": {"some": "current_humidity_changed_above_for"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"trigger": {
|
||||
"platform": "device",
|
||||
|
@ -302,37 +347,76 @@ async def test_if_fires_on_state_change(
|
|||
)
|
||||
|
||||
# Fake that the humidity target is changing
|
||||
hass.states.async_set(entry.entity_id, STATE_ON, {const.ATTR_HUMIDITY: 7})
|
||||
hass.states.async_set(
|
||||
entry.entity_id,
|
||||
STATE_ON,
|
||||
{const.ATTR_HUMIDITY: 7, const.ATTR_CURRENT_HUMIDITY: 35},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "target_humidity_changed_below"
|
||||
|
||||
# Fake that the humidity target is changing
|
||||
hass.states.async_set(entry.entity_id, STATE_ON, {const.ATTR_HUMIDITY: 37})
|
||||
# Fake that the current humidity is changing
|
||||
hass.states.async_set(
|
||||
entry.entity_id,
|
||||
STATE_ON,
|
||||
{const.ATTR_HUMIDITY: 7, const.ATTR_CURRENT_HUMIDITY: 18},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
assert calls[1].data["some"] == "target_humidity_changed_above"
|
||||
assert calls[1].data["some"] == "current_humidity_changed_below"
|
||||
|
||||
# Fake that the humidity target is changing
|
||||
hass.states.async_set(
|
||||
entry.entity_id,
|
||||
STATE_ON,
|
||||
{const.ATTR_HUMIDITY: 37, const.ATTR_CURRENT_HUMIDITY: 18},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 3
|
||||
assert calls[2].data["some"] == "target_humidity_changed_above"
|
||||
|
||||
# Fake that the current humidity is changing
|
||||
hass.states.async_set(
|
||||
entry.entity_id,
|
||||
STATE_ON,
|
||||
{const.ATTR_HUMIDITY: 37, const.ATTR_CURRENT_HUMIDITY: 41},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 4
|
||||
assert calls[3].data["some"] == "current_humidity_changed_above"
|
||||
|
||||
# Wait 6 minutes
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + datetime.timedelta(minutes=6))
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 3
|
||||
assert calls[2].data["some"] == "target_humidity_changed_above_for"
|
||||
assert len(calls) == 6
|
||||
assert {calls[4].data["some"], calls[5].data["some"]} == {
|
||||
"current_humidity_changed_above_for",
|
||||
"target_humidity_changed_above_for",
|
||||
}
|
||||
|
||||
# Fake turn off
|
||||
hass.states.async_set(entry.entity_id, STATE_OFF, {const.ATTR_HUMIDITY: 37})
|
||||
hass.states.async_set(
|
||||
entry.entity_id,
|
||||
STATE_OFF,
|
||||
{const.ATTR_HUMIDITY: 37, const.ATTR_CURRENT_HUMIDITY: 41},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 5
|
||||
assert {calls[3].data["some"], calls[4].data["some"]} == {
|
||||
assert len(calls) == 8
|
||||
assert {calls[6].data["some"], calls[7].data["some"]} == {
|
||||
"turn_off device - humidifier.test_5678 - on - off - None",
|
||||
"turn_on_or_off device - humidifier.test_5678 - on - off - None",
|
||||
}
|
||||
|
||||
# Fake turn on
|
||||
hass.states.async_set(entry.entity_id, STATE_ON, {const.ATTR_HUMIDITY: 37})
|
||||
hass.states.async_set(
|
||||
entry.entity_id,
|
||||
STATE_ON,
|
||||
{const.ATTR_HUMIDITY: 37, const.ATTR_CURRENT_HUMIDITY: 41},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 7
|
||||
assert {calls[5].data["some"], calls[6].data["some"]} == {
|
||||
assert len(calls) == 10
|
||||
assert {calls[8].data["some"], calls[9].data["some"]} == {
|
||||
"turn_on device - humidifier.test_5678 - off - on - None",
|
||||
"turn_on_or_off device - humidifier.test_5678 - off - on - None",
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue