Merge pull request #36579 from home-assistant/110.6

This commit is contained in:
Paulus Schoutsen 2020-06-08 11:15:35 -07:00 committed by GitHub
commit a9287b7117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 4 deletions

View File

@ -352,7 +352,7 @@ async def webhook_enable_encryption(hass, config_entry, data):
vol.Required(ATTR_SENSOR_TYPE): vol.In(SENSOR_TYPES),
vol.Required(ATTR_SENSOR_UNIQUE_ID): cv.string,
vol.Optional(ATTR_SENSOR_UOM): cv.string,
vol.Required(ATTR_SENSOR_STATE): vol.Any(bool, str, int, float),
vol.Required(ATTR_SENSOR_STATE): vol.Any(None, bool, str, int, float),
vol.Optional(ATTR_SENSOR_ICON, default="mdi:cellphone"): cv.icon,
}
)
@ -414,7 +414,7 @@ async def webhook_update_sensor_states(hass, config_entry, data):
{
vol.Optional(ATTR_SENSOR_ATTRIBUTES, default={}): dict,
vol.Optional(ATTR_SENSOR_ICON, default="mdi:cellphone"): cv.icon,
vol.Required(ATTR_SENSOR_STATE): vol.Any(bool, str, int, float),
vol.Required(ATTR_SENSOR_STATE): vol.Any(None, bool, str, int, float),
vol.Required(ATTR_SENSOR_TYPE): vol.In(SENSOR_TYPES),
vol.Required(ATTR_SENSOR_UNIQUE_ID): cv.string,
}

View File

@ -1,7 +1,7 @@
"""Constants used by Home Assistant components."""
MAJOR_VERSION = 0
MINOR_VERSION = 110
PATCH_VERSION = "5"
PATCH_VERSION = "6"
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__ = f"{__short_version__}.{PATCH_VERSION}"
REQUIRED_PYTHON_VER = (3, 7, 0)

View File

@ -2,7 +2,7 @@
import logging
from homeassistant.const import UNIT_PERCENTAGE
from homeassistant.const import STATE_UNKNOWN, UNIT_PERCENTAGE
from homeassistant.helpers import device_registry
_LOGGER = logging.getLogger(__name__)
@ -128,3 +128,80 @@ async def test_sensor_id_no_dupes(hass, create_registrations, webhook_client):
dupe_json = await dupe_resp.json()
assert dupe_json["success"] is False
assert dupe_json["error"]["code"] == "duplicate_unique_id"
async def test_register_sensor_no_state(hass, create_registrations, webhook_client):
"""Test that sensors can be registered, when there is no (unknown) state."""
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 == 201
json = await reg_resp.json()
assert json == {"success": True}
await hass.async_block_till_done()
entity = hass.states.get("sensor.test_1_battery_state")
assert entity is not None
assert entity.domain == "sensor"
assert entity.name == "Test 1 Battery State"
assert entity.state == STATE_UNKNOWN
async def test_update_sensor_no_state(hass, create_registrations, webhook_client):
"""Test that sensors can be updated, when there is no (unknown) state."""
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": 100,
"type": "sensor",
"unique_id": "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_battery_state")
assert entity is not None
assert entity.state == "100"
update_resp = await webhook_client.post(
webhook_url,
json={
"type": "update_sensor_states",
"data": [{"state": None, "type": "sensor", "unique_id": "battery_state"}],
},
)
assert update_resp.status == 200
json = await update_resp.json()
assert json == {"battery_state": {"success": True}}
updated_entity = hass.states.get("sensor.test_1_battery_state")
assert updated_entity.state == STATE_UNKNOWN