mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
parent
0f2097595e
commit
4f63eab453
@ -32,7 +32,7 @@ async def test_temperature_sensor(hass: HomeAssistant):
|
|||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(f"{DOMAIN}.test")
|
state = hass.states.get(f"{DOMAIN}.test_temperature")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == str(
|
assert state.state == str(
|
||||||
test_gateway.devices["Test"]
|
test_gateway.devices["Test"]
|
||||||
@ -56,18 +56,21 @@ async def test_battery_sensor(hass: HomeAssistant):
|
|||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(f"{DOMAIN}.test_2")
|
state = hass.states.get(f"{DOMAIN}.test_battery_level")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == str(test_gateway.devices["Test"].battery_level)
|
assert state.state == str(test_gateway.devices["Test"].battery_level)
|
||||||
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
||||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
|
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
|
||||||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.BATTERY
|
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.BATTERY
|
||||||
assert er.async_get(f"{DOMAIN}.test_2").entity_category is EntityCategory.DIAGNOSTIC
|
assert (
|
||||||
|
er.async_get(f"{DOMAIN}.test_battery_level").entity_category
|
||||||
|
is EntityCategory.DIAGNOSTIC
|
||||||
|
)
|
||||||
|
|
||||||
# Emulate websocket message: value changed
|
# Emulate websocket message: value changed
|
||||||
test_gateway.publisher.dispatch("Test", ("Test", 10, "battery_level"))
|
test_gateway.publisher.dispatch("Test", ("Test", 10, "battery_level"))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get(f"{DOMAIN}.test_2").state == "10"
|
assert hass.states.get(f"{DOMAIN}.test_battery_level").state == "10"
|
||||||
|
|
||||||
|
|
||||||
async def test_consumption_sensor(hass: HomeAssistant):
|
async def test_consumption_sensor(hass: HomeAssistant):
|
||||||
@ -81,7 +84,7 @@ async def test_consumption_sensor(hass: HomeAssistant):
|
|||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(f"{DOMAIN}.test_current")
|
state = hass.states.get(f"{DOMAIN}.test_current_consumption")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == str(
|
assert state.state == str(
|
||||||
test_gateway.devices["Test"].consumption_property["devolo.Meter:Test"].current
|
test_gateway.devices["Test"].consumption_property["devolo.Meter:Test"].current
|
||||||
@ -89,7 +92,7 @@ async def test_consumption_sensor(hass: HomeAssistant):
|
|||||||
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT
|
||||||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.POWER
|
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.POWER
|
||||||
|
|
||||||
state = hass.states.get(f"{DOMAIN}.test_total")
|
state = hass.states.get(f"{DOMAIN}.test_total_consumption")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == str(
|
assert state.state == str(
|
||||||
test_gateway.devices["Test"].consumption_property["devolo.Meter:Test"].total
|
test_gateway.devices["Test"].consumption_property["devolo.Meter:Test"].total
|
||||||
@ -101,14 +104,18 @@ async def test_consumption_sensor(hass: HomeAssistant):
|
|||||||
test_gateway.devices["Test"].consumption_property["devolo.Meter:Test"].total = 50.0
|
test_gateway.devices["Test"].consumption_property["devolo.Meter:Test"].total = 50.0
|
||||||
test_gateway.publisher.dispatch("Test", ("devolo.Meter:Test", 50.0))
|
test_gateway.publisher.dispatch("Test", ("devolo.Meter:Test", 50.0))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get(f"{DOMAIN}.test_total").state == "50.0"
|
assert hass.states.get(f"{DOMAIN}.test_total_consumption").state == "50.0"
|
||||||
|
|
||||||
# Emulate websocket message: device went offline
|
# Emulate websocket message: device went offline
|
||||||
test_gateway.devices["Test"].status = 1
|
test_gateway.devices["Test"].status = 1
|
||||||
test_gateway.publisher.dispatch("Test", ("Status", False, "status"))
|
test_gateway.publisher.dispatch("Test", ("Status", False, "status"))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get(f"{DOMAIN}.test_current").state == STATE_UNAVAILABLE
|
assert (
|
||||||
assert hass.states.get(f"{DOMAIN}.test_total").state == STATE_UNAVAILABLE
|
hass.states.get(f"{DOMAIN}.test_current_consumption").state == STATE_UNAVAILABLE
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
hass.states.get(f"{DOMAIN}.test_total_consumption").state == STATE_UNAVAILABLE
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_voltage_sensor(hass: HomeAssistant):
|
async def test_voltage_sensor(hass: HomeAssistant):
|
||||||
@ -122,7 +129,7 @@ async def test_voltage_sensor(hass: HomeAssistant):
|
|||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(f"{DOMAIN}.test")
|
state = hass.states.get(f"{DOMAIN}.test_voltage")
|
||||||
assert state is None
|
assert state is None
|
||||||
|
|
||||||
|
|
||||||
@ -140,14 +147,14 @@ async def test_sensor_change(hass: HomeAssistant):
|
|||||||
# Emulate websocket message: value changed
|
# Emulate websocket message: value changed
|
||||||
test_gateway.publisher.dispatch("Test", ("devolo.MultiLevelSensor:Test", 50.0))
|
test_gateway.publisher.dispatch("Test", ("devolo.MultiLevelSensor:Test", 50.0))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get(f"{DOMAIN}.test")
|
state = hass.states.get(f"{DOMAIN}.test_temperature")
|
||||||
assert state.state == "50.0"
|
assert state.state == "50.0"
|
||||||
|
|
||||||
# Emulate websocket message: device went offline
|
# Emulate websocket message: device went offline
|
||||||
test_gateway.devices["Test"].status = 1
|
test_gateway.devices["Test"].status = 1
|
||||||
test_gateway.publisher.dispatch("Test", ("Status", False, "status"))
|
test_gateway.publisher.dispatch("Test", ("Status", False, "status"))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert hass.states.get(f"{DOMAIN}.test").state == STATE_UNAVAILABLE
|
assert hass.states.get(f"{DOMAIN}.test_temperature").state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
async def test_remove_from_hass(hass: HomeAssistant):
|
async def test_remove_from_hass(hass: HomeAssistant):
|
||||||
@ -161,7 +168,7 @@ async def test_remove_from_hass(hass: HomeAssistant):
|
|||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get(f"{DOMAIN}.test")
|
state = hass.states.get(f"{DOMAIN}.test_temperature")
|
||||||
assert state is not None
|
assert state is not None
|
||||||
await hass.config_entries.async_remove(entry.entry_id)
|
await hass.config_entries.async_remove(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user