Skip to content

Commit

Permalink
[bug-fix] use a default value for device name (#102)
Browse files Browse the repository at this point in the history
* use a default value for device name

* allow configurable names
  • Loading branch information
domanchi authored Dec 8, 2023
1 parent ee89dc9 commit 414c6b3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 10 additions & 3 deletions custom_components/dyson_local/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async def async_step_host(self, info: Optional[dict] = None):
self._device_info.serial,
self._device_info.credential,
self._device_info.product_type,
self._device_info.name,
info.get(CONF_NAME),
info.get(CONF_HOST),
)
except CannotConnect:
Expand All @@ -319,15 +319,22 @@ async def async_step_host(self, info: Optional[dict] = None):
errors["base"] = "cannot_find"
else:
return self.async_create_entry(
title=self._device_info.name,
title=info.get(CONF_NAME),
data=data,
)

# NOTE: Sometimes, the device is not named. In these situations,
# default to using the unique serial number as the name.
name = self._device_info.name or self._device_info.serial

info = info or {}
return self.async_show_form(
step_id="host",
data_schema=vol.Schema(
{vol.Optional(CONF_HOST, default=info.get(CONF_HOST, "")): str}
{
vol.Optional(CONF_HOST, default=info.get(CONF_HOST, "")): str,
vol.Optional(CONF_NAME, default=info.get(CONF_NAME, name)): str,
}
),
errors=errors,
)
Expand Down
5 changes: 3 additions & 2 deletions custom_components/dyson_local/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
},
"host": {
"data": {
"host": "Device IP Address (Optional)"
"host": "Device IP Address (Optional)",
"name": "Device Name"
}
},
"email": {
Expand Down Expand Up @@ -70,4 +71,4 @@
"already_configured": "Device already configured"
}
}
}
}

0 comments on commit 414c6b3

Please sign in to comment.