-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Kuler Sky Bluetooth floor lamp integration #42372
Conversation
5ecd51f
to
c6a717f
Compare
_LOGGER.error("Exception scanning for Kuler Sky devices", exc_info=exc) | ||
return self.async_abort(reason="scan_error") | ||
|
||
options = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why allow the user to pick? We could replace this config flow with https://developers.home-assistant.io/docs/config_entries_config_flow_handler#discoverable-integrations-that-require-no-authentication and then have the light platform set them all up. The user can disable the entities of the lights they don't want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I could have sworn I commented this somewhere, but I don't see it. 🤦♀️ The problem with these devices is they don't expose any identifying information, at least nothing available to the underlying pygatt
library. So the best that pykulersky
can do is discover all nearby bluetooth devices. (I need to update that library discover
method name to make it more clear) So the options we've got are either have the user pick the correct device, or attempt to connect to each discovered bluetooth device, which could potentially leave the user waiting at the spinner for a while if there are a lot of other bluetooth devices in the vicinity. I'm OK with either option, but those are the tradeoffs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review!
I pushed up some comments, and renamed the upstream method so that the current behavior is at least more clear when reading the code. Still happy to switch to plan B if you'd prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The discovery config flow only requires a single light to be discovered to set up the config flow. (Just wants to make sure a device can be found).
After that it finishes the flow and lights will be added to Home Assistant as discovery picks up more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that having the user pick a bluetooth address is putting burden on the user. Having a user wait while we figure out if they have any device is a lot better experience compared to having the user set up each individual device and having to figure out their addresses too (noticed we have name too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even discovering the first light could be really slow though, since we'll have to attempt a connection with every nearby bluetooth device before we know if it's a valid device. I'll switch it over though. Sounds like simple but slow is the preferred solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can change the discovery flow to just check if Bluetooth works ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I like that idea! Should be a quick test to ensure the bluetooth stack is working, and the devices will be available once they're discovered. 👍
if brightness == 0 and white_value == 0 and not kwargs: | ||
# If the light would be off, and no additional parameters were | ||
# passed, just turn the light on full brightness. | ||
brightness = 255 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to pass nothing, and it turns on with the last values before it was turned off?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately these lights don't have that capability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Laaaaaaaaaaame
@@ -0,0 +1,20 @@ | |||
{ | |||
"title": "Kuler Sky", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this, HA defaults to the manifest title. Since it's a brandname, we don't want it translated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Few minor comments!
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
6c15a74
to
6dab4c5
Compare
fc06d2e
to
2d44a3f
Compare
OK, updated to the new discovery strategy! It's looking a lot cleaner now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay. My notifications are flooded.
Tagged it so it will be in the next release :) |
No worries. Thanks for your help! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Some small comments.
|
||
|
||
config_entry_flow.register_discovery_flow( | ||
DOMAIN, "Kuler Sky", _async_has_devices, config_entries.CONN_CLASS_UNKNOWN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update the connection class to be one of the standard classes except unknown, eg CONN_CLASS_LOCAL_POLL
.
core/homeassistant/config_entries.py
Lines 85 to 89 in 4c7e17c
CONN_CLASS_CLOUD_PUSH = "cloud_push" | |
CONN_CLASS_CLOUD_POLL = "cloud_poll" | |
CONN_CLASS_LOCAL_PUSH = "local_push" | |
CONN_CLASS_LOCAL_POLL = "local_poll" | |
CONN_CLASS_ASSUMED = "assumed" |
# device. If the vendor's app is connected to the light when | ||
# home assistant tries to connect, this connection will fail. | ||
await hass.async_add_executor_job(light.connect) | ||
await hass.async_add_executor_job(light.get_color) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could optimize this a bit by wrapping both calls inside of one function that we schedule on the executor.
async_add_entities([KulerskyLight(light)], update_before_add=True) | ||
|
||
# Start initial discovery | ||
hass.async_add_job(discover) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use hass.async_create_task
instead. hass.async_add_job
is legacy for general use.
Thanks for the follow-up @MartinHjelmare ! I've pushed up a cleanup PR here #43901 |
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Proposed change
This PR introduces a new component for Brightech Kuler Sky bluetooth floor lamps. https://smile.amazon.com/Brightech-Kuler-Sky-Torchiere-Adjustable/dp/B01LDT39AE
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: