Disable both option in Airgradient select (#118702)

This commit is contained in:
Joost Lekkerkerker
2024-06-03 21:25:43 +02:00
committed by Franck Nijhof
parent 54425b756e
commit ea85ed6992
6 changed files with 61 additions and 19 deletions
+23 -1
View File
@@ -42,11 +42,33 @@ def mock_airgradient_client() -> Generator[AsyncMock, None, None]:
load_fixture("current_measures.json", DOMAIN)
)
client.get_config.return_value = Config.from_json(
load_fixture("get_config.json", DOMAIN)
load_fixture("get_config_local.json", DOMAIN)
)
yield client
@pytest.fixture
def mock_new_airgradient_client(
mock_airgradient_client: AsyncMock,
) -> Generator[AsyncMock, None, None]:
"""Mock a new AirGradient client."""
mock_airgradient_client.get_config.return_value = Config.from_json(
load_fixture("get_config.json", DOMAIN)
)
return mock_airgradient_client
@pytest.fixture
def mock_cloud_airgradient_client(
mock_airgradient_client: AsyncMock,
) -> Generator[AsyncMock, None, None]:
"""Mock a new AirGradient client."""
mock_airgradient_client.get_config.return_value = Config.from_json(
load_fixture("get_config_cloud.json", DOMAIN)
)
return mock_airgradient_client
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
"""Mock a config entry."""
@@ -0,0 +1,13 @@
{
"country": "DE",
"pmStandard": "ugm3",
"ledBarMode": "co2",
"displayMode": "on",
"abcDays": 8,
"tvocLearningOffset": 12,
"noxLearningOffset": 12,
"mqttBrokerUrl": "",
"temperatureUnit": "c",
"configurationControl": "cloud",
"postDataToAirGradient": true
}
@@ -0,0 +1,13 @@
{
"country": "DE",
"pmStandard": "ugm3",
"ledBarMode": "co2",
"displayMode": "on",
"abcDays": 8,
"tvocLearningOffset": 12,
"noxLearningOffset": 12,
"mqttBrokerUrl": "",
"temperatureUnit": "c",
"configurationControl": "local",
"postDataToAirGradient": true
}
@@ -8,7 +8,6 @@
'options': list([
'cloud',
'local',
'both',
]),
}),
'config_entry_id': <ANY>,
@@ -45,7 +44,6 @@
'options': list([
'cloud',
'local',
'both',
]),
}),
'context': <ANY>,
@@ -53,7 +51,7 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'both',
'state': 'local',
})
# ---
# name: test_all_entities[select.airgradient_display_temperature_unit-entry]
@@ -120,7 +118,6 @@
'options': list([
'cloud',
'local',
'both',
]),
}),
'config_entry_id': <ANY>,
@@ -157,7 +154,6 @@
'options': list([
'cloud',
'local',
'both',
]),
}),
'context': <ANY>,
@@ -165,6 +161,6 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'both',
'state': 'local',
})
# ---
+4 -8
View File
@@ -77,16 +77,12 @@ async def test_setting_value(
async def test_setting_protected_value(
hass: HomeAssistant,
mock_airgradient_client: AsyncMock,
mock_cloud_airgradient_client: AsyncMock,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test setting protected value."""
await setup_integration(hass, mock_config_entry)
mock_airgradient_client.get_config.return_value.configuration_control = (
ConfigurationControl.CLOUD
)
with pytest.raises(ServiceValidationError):
await hass.services.async_call(
SELECT_DOMAIN,
@@ -97,9 +93,9 @@ async def test_setting_protected_value(
},
blocking=True,
)
mock_airgradient_client.set_temperature_unit.assert_not_called()
mock_cloud_airgradient_client.set_temperature_unit.assert_not_called()
mock_airgradient_client.get_config.return_value.configuration_control = (
mock_cloud_airgradient_client.get_config.return_value.configuration_control = (
ConfigurationControl.LOCAL
)
@@ -112,4 +108,4 @@ async def test_setting_protected_value(
},
blocking=True,
)
mock_airgradient_client.set_temperature_unit.assert_called_once_with("c")
mock_cloud_airgradient_client.set_temperature_unit.assert_called_once_with("c")