Add device_class and state_class in config flow for SQL (#95020)

* Add device_class and state_class in config flow for SQL

* Update when selected NONE_SENTINEL

* Add tests

* Use SensorDeviceClass and SensorStateClass in tests

* Add volatile_organic_compounds_parts in strings selector

* Add test_attributes_from_entry_config

* Remove test_attributes_from_entry_config and complement test_device_state_class

* Add test_attributes_from_entry_config in test_sensor.py
This commit is contained in:
dougiteixeira 2023-07-08 16:00:22 -03:00 committed by GitHub
parent b2bf360297
commit 4b1d096e6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 264 additions and 7 deletions

View file

@ -457,3 +457,47 @@ async def test_engine_is_disposed_at_stop(
await hass.async_stop()
assert mock_engine_dispose.call_count == 2
async def test_attributes_from_entry_config(
recorder_mock: Recorder, hass: HomeAssistant
) -> None:
"""Test attributes from entry config."""
await init_integration(
hass,
config={
"name": "Get Value - With",
"query": "SELECT 5 as value",
"column": "value",
"unit_of_measurement": "MiB",
"device_class": SensorDeviceClass.DATA_SIZE,
"state_class": SensorStateClass.TOTAL,
},
entry_id="8693d4782ced4fb1ecca4743f29ab8f1",
)
state = hass.states.get("sensor.get_value_with")
assert state.state == "5"
assert state.attributes["value"] == 5
assert state.attributes["unit_of_measurement"] == "MiB"
assert state.attributes["device_class"] == SensorDeviceClass.DATA_SIZE
assert state.attributes["state_class"] == SensorStateClass.TOTAL
await init_integration(
hass,
config={
"name": "Get Value - Without",
"query": "SELECT 5 as value",
"column": "value",
"unit_of_measurement": "MiB",
},
entry_id="7aec7cd8045fba4778bb0621469e3cd9",
)
state = hass.states.get("sensor.get_value_without")
assert state.state == "5"
assert state.attributes["value"] == 5
assert state.attributes["unit_of_measurement"] == "MiB"
assert "device_class" not in state.attributes
assert "state_class" not in state.attributes