Fix bad falsy-check in homeassistant.set_location service (#129389)

This commit is contained in:
Erik Montnemery 2024-10-29 16:11:48 +01:00 committed by GitHub
parent 505a4bfc34
commit cce925c06c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View File

@ -282,7 +282,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
"longitude": call.data[ATTR_LONGITUDE],
}
if elevation := call.data.get(ATTR_ELEVATION):
if (elevation := call.data.get(ATTR_ELEVATION)) is not None:
service_data["elevation"] = elevation
await hass.config.async_update(**service_data)

View File

@ -242,7 +242,7 @@ async def test_setting_location(hass: HomeAssistant) -> None:
assert elevation != 50
await hass.services.async_call(
"homeassistant",
"set_location",
SERVICE_SET_LOCATION,
{"latitude": 30, "longitude": 40},
blocking=True,
)
@ -253,12 +253,24 @@ async def test_setting_location(hass: HomeAssistant) -> None:
await hass.services.async_call(
"homeassistant",
"set_location",
SERVICE_SET_LOCATION,
{"latitude": 30, "longitude": 40, "elevation": 50},
blocking=True,
)
assert hass.config.latitude == 30
assert hass.config.longitude == 40
assert hass.config.elevation == 50
await hass.services.async_call(
"homeassistant",
SERVICE_SET_LOCATION,
{"latitude": 30, "longitude": 40, "elevation": 0},
blocking=True,
)
assert hass.config.latitude == 30
assert hass.config.longitude == 40
assert hass.config.elevation == 0
async def test_require_admin(
hass: HomeAssistant, hass_read_only_user: MockUser