Skip to content

Commit

Permalink
Set parameter only if service call data includes elevation
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieger committed Sep 9, 2023
1 parent 44b6094 commit ecd317b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions homeassistant/components/homeassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,19 @@ async def async_handle_reload_config(call: ha.ServiceCall) -> None:
async def async_set_location(call: ha.ServiceCall) -> None:
"""Service handler to set location."""
await hass.config.async_update(
latitude=call.data[ATTR_LATITUDE],
longitude=call.data[ATTR_LONGITUDE],
elevation=call.data.get(ATTR_ELEVATION, None),
latitude=call.data[ATTR_LATITUDE], longitude=call.data[ATTR_LONGITUDE]
)

service_data = {
"latitude": call.data[ATTR_LATITUDE],
"longitude": call.data[ATTR_LONGITUDE],
}

if call.data.get(ATTR_ELEVATION):
service_data["elevation"] = call.data[ATTR_ELEVATION]

await hass.config.async_update(**service_data)

async_register_admin_service(
hass,
ha.DOMAIN,
Expand Down
2 changes: 1 addition & 1 deletion tests/components/homeassistant/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ async def test_setting_location(hass: HomeAssistant) -> None:
{"latitude": 30, "longitude": 40},
blocking=True,
)
assert len(events) == 1
assert len(events) == 2
assert hass.config.latitude == 30
assert hass.config.longitude == 40
assert hass.config.elevation != 50
Expand Down

0 comments on commit ecd317b

Please sign in to comment.