Fix mobile_app missing state in sensor registration (#36604)
This commit is contained in:
parent
854bdfb6f2
commit
2abd3844cf
2 changed files with 28 additions and 1 deletions
|
@ -356,7 +356,9 @@ async def webhook_enable_encryption(hass, config_entry, data):
|
||||||
vol.Required(ATTR_SENSOR_TYPE): vol.In(SENSOR_TYPES),
|
vol.Required(ATTR_SENSOR_TYPE): vol.In(SENSOR_TYPES),
|
||||||
vol.Required(ATTR_SENSOR_UNIQUE_ID): cv.string,
|
vol.Required(ATTR_SENSOR_UNIQUE_ID): cv.string,
|
||||||
vol.Optional(ATTR_SENSOR_UOM): cv.string,
|
vol.Optional(ATTR_SENSOR_UOM): cv.string,
|
||||||
vol.Required(ATTR_SENSOR_STATE): vol.Any(None, bool, str, int, float),
|
vol.Optional(ATTR_SENSOR_STATE, default=None): vol.Any(
|
||||||
|
None, bool, str, int, float
|
||||||
|
),
|
||||||
vol.Optional(ATTR_SENSOR_ICON, default="mdi:cellphone"): cv.icon,
|
vol.Optional(ATTR_SENSOR_ICON, default="mdi:cellphone"): cv.icon,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -188,6 +188,31 @@ async def test_register_sensor_no_state(hass, create_registrations, webhook_clie
|
||||||
assert entity.name == "Test 1 Battery State"
|
assert entity.name == "Test 1 Battery State"
|
||||||
assert entity.state == STATE_UNKNOWN
|
assert entity.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
reg_resp = await webhook_client.post(
|
||||||
|
webhook_url,
|
||||||
|
json={
|
||||||
|
"type": "register_sensor",
|
||||||
|
"data": {
|
||||||
|
"name": "Backup Battery State",
|
||||||
|
"type": "sensor",
|
||||||
|
"unique_id": "backup_battery_state",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert reg_resp.status == 201
|
||||||
|
|
||||||
|
json = await reg_resp.json()
|
||||||
|
assert json == {"success": True}
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
entity = hass.states.get("sensor.test_1_backup_battery_state")
|
||||||
|
assert entity
|
||||||
|
|
||||||
|
assert entity.domain == "sensor"
|
||||||
|
assert entity.name == "Test 1 Backup Battery State"
|
||||||
|
assert entity.state == STATE_UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
async def test_update_sensor_no_state(hass, create_registrations, webhook_client):
|
async def test_update_sensor_no_state(hass, create_registrations, webhook_client):
|
||||||
"""Test that sensors can be updated, when there is no (unknown) state."""
|
"""Test that sensors can be updated, when there is no (unknown) state."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue