Mobile app to notify when sensor is disabled (#71561)
* Mobile app to notify when sensor is disabled * Add entity status to get_config * Allow overriding enabled/disabled
This commit is contained in:
parent
e4573273dc
commit
0b09376360
5 changed files with 162 additions and 13 deletions
|
@ -355,7 +355,7 @@ async def test_default_disabling_entity(hass, create_registrations, webhook_clie
|
|||
"name": "Battery State",
|
||||
"type": "sensor",
|
||||
"unique_id": "battery_state",
|
||||
"default_disabled": True,
|
||||
"disabled": True,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
@ -373,3 +373,70 @@ async def test_default_disabling_entity(hass, create_registrations, webhook_clie
|
|||
er.async_get(hass).async_get("sensor.test_1_battery_state").disabled_by
|
||||
== er.RegistryEntryDisabler.INTEGRATION
|
||||
)
|
||||
|
||||
|
||||
async def test_updating_disabled_sensor(hass, create_registrations, webhook_client):
|
||||
"""Test that sensors return error if disabled in instance."""
|
||||
webhook_id = create_registrations[1]["webhook_id"]
|
||||
webhook_url = f"/api/webhook/{webhook_id}"
|
||||
|
||||
reg_resp = await webhook_client.post(
|
||||
webhook_url,
|
||||
json={
|
||||
"type": "register_sensor",
|
||||
"data": {
|
||||
"name": "Battery State",
|
||||
"state": None,
|
||||
"type": "sensor",
|
||||
"unique_id": "battery_state",
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
assert reg_resp.status == HTTPStatus.CREATED
|
||||
|
||||
update_resp = await webhook_client.post(
|
||||
webhook_url,
|
||||
json={
|
||||
"type": "update_sensor_states",
|
||||
"data": [
|
||||
{
|
||||
"icon": "mdi:battery-unknown",
|
||||
"state": 123,
|
||||
"type": "sensor",
|
||||
"unique_id": "battery_state",
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
assert update_resp.status == HTTPStatus.OK
|
||||
|
||||
json = await update_resp.json()
|
||||
assert json["battery_state"]["success"] is True
|
||||
assert "is_disabled" not in json["battery_state"]
|
||||
|
||||
er.async_get(hass).async_update_entity(
|
||||
"sensor.test_1_battery_state", disabled_by=er.RegistryEntryDisabler.USER
|
||||
)
|
||||
|
||||
update_resp = await webhook_client.post(
|
||||
webhook_url,
|
||||
json={
|
||||
"type": "update_sensor_states",
|
||||
"data": [
|
||||
{
|
||||
"icon": "mdi:battery-unknown",
|
||||
"state": 123,
|
||||
"type": "sensor",
|
||||
"unique_id": "battery_state",
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
assert update_resp.status == HTTPStatus.OK
|
||||
|
||||
json = await update_resp.json()
|
||||
assert json["battery_state"]["success"] is True
|
||||
assert json["battery_state"]["is_disabled"] is True
|
||||
|
|
|
@ -254,10 +254,30 @@ async def test_webhook_handle_get_zones(hass, create_registrations, webhook_clie
|
|||
|
||||
async def test_webhook_handle_get_config(hass, create_registrations, webhook_client):
|
||||
"""Test that we can get config properly."""
|
||||
resp = await webhook_client.post(
|
||||
"/api/webhook/{}".format(create_registrations[1]["webhook_id"]),
|
||||
json={"type": "get_config"},
|
||||
)
|
||||
webhook_id = create_registrations[1]["webhook_id"]
|
||||
webhook_url = f"/api/webhook/{webhook_id}"
|
||||
|
||||
# Create two entities
|
||||
for sensor in (
|
||||
{
|
||||
"name": "Battery State",
|
||||
"type": "sensor",
|
||||
"unique_id": "battery-state-id",
|
||||
},
|
||||
{
|
||||
"name": "Battery Charging",
|
||||
"type": "sensor",
|
||||
"unique_id": "battery-charging-id",
|
||||
"disabled": True,
|
||||
},
|
||||
):
|
||||
reg_resp = await webhook_client.post(
|
||||
webhook_url,
|
||||
json={"type": "register_sensor", "data": sensor},
|
||||
)
|
||||
assert reg_resp.status == HTTPStatus.CREATED
|
||||
|
||||
resp = await webhook_client.post(webhook_url, json={"type": "get_config"})
|
||||
|
||||
assert resp.status == HTTPStatus.OK
|
||||
|
||||
|
@ -279,6 +299,11 @@ async def test_webhook_handle_get_config(hass, create_registrations, webhook_cli
|
|||
"components": hass_config["components"],
|
||||
"version": hass_config["version"],
|
||||
"theme_color": "#03A9F4", # Default frontend theme color
|
||||
"entities": {
|
||||
"mock-device-id": {"disabled": False},
|
||||
"battery-state-id": {"disabled": False},
|
||||
"battery-charging-id": {"disabled": True},
|
||||
},
|
||||
}
|
||||
|
||||
assert expected_dict == json
|
||||
|
@ -902,6 +927,7 @@ async def test_reregister_sensor(hass, create_registrations, webhook_client):
|
|||
assert entry.unit_of_measurement is None
|
||||
assert entry.entity_category is None
|
||||
assert entry.original_icon == "mdi:cellphone"
|
||||
assert entry.disabled_by is None
|
||||
|
||||
reg_resp = await webhook_client.post(
|
||||
webhook_url,
|
||||
|
@ -917,6 +943,7 @@ async def test_reregister_sensor(hass, create_registrations, webhook_client):
|
|||
"entity_category": "diagnostic",
|
||||
"icon": "mdi:new-icon",
|
||||
"unit_of_measurement": "%",
|
||||
"disabled": True,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
@ -928,3 +955,21 @@ async def test_reregister_sensor(hass, create_registrations, webhook_client):
|
|||
assert entry.unit_of_measurement == "%"
|
||||
assert entry.entity_category == "diagnostic"
|
||||
assert entry.original_icon == "mdi:new-icon"
|
||||
assert entry.disabled_by == er.RegistryEntryDisabler.INTEGRATION
|
||||
|
||||
reg_resp = await webhook_client.post(
|
||||
webhook_url,
|
||||
json={
|
||||
"type": "register_sensor",
|
||||
"data": {
|
||||
"name": "New Name",
|
||||
"type": "sensor",
|
||||
"unique_id": "abcd",
|
||||
"disabled": False,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
assert reg_resp.status == HTTPStatus.CREATED
|
||||
entry = ent_reg.async_get("sensor.test_1_battery_state")
|
||||
assert entry.disabled_by is None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue