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 support for Opple light #16765
Add support for Opple light #16765
Conversation
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 add unique_id
property and return the mac address. This will make the integration more user friendly.
}) | ||
|
||
|
||
def setup_platform(hass, config, add_devices, discovery_info=None): |
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.
Rename add_devices
to add_entities
.
def setup_platform(hass, config, add_devices, discovery_info=None): | ||
"""Set up Opple light platform.""" | ||
name = config.get('name') | ||
host = config.get('host') |
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.
Use dict[key]
for required config keys.
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.
Use the constants used in the config schema.
self._brightness = None | ||
self._color_temp = None | ||
|
||
_LOGGER.debug("init light %s %s", self._device.ip, self._device.mac) |
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.
Capitalize start word of log messages.
"""Instruct the light to turn on.""" | ||
_LOGGER.debug("Turn on light %s %s", self._device.ip, kwargs) | ||
if not self.is_on: | ||
self._is_on = self._device.power_on = True |
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.
Let update
change state holding instance attributes. It will be called directly after the method call.
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'm sorry I didn't catch your meaning
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.
Change the line to:
self._device.power_on = True
is_on
will be updated in update
.
self._brightness = self._device.brightness | ||
self._color_temp = self._device.color_temperature | ||
|
||
if not self.available: |
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.
Only log one message when the device changes availability state, not on each update if state is the same.
The config section in the PR description is not accurate. |
return | ||
|
||
if not self.available: | ||
_LOGGER.debug("Light %s is offline", self._device.ip) |
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 consider raising the logging level to warning, depending on how often we think this will occur.
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.
When people turn off their light through a wall switch, the light goes offline, so it's pretty common. So I think "debug level" is just fine.
|
||
def setup_platform(hass, config, add_entities, discovery_info=None): | ||
"""Set up Opple light platform.""" | ||
name = config['name'] |
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.
Use CONF_NAME
.
def setup_platform(hass, config, add_entities, discovery_info=None): | ||
"""Set up Opple light platform.""" | ||
name = config['name'] | ||
host = config['host'] |
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.
Use CONF_HOST
.
self._brightness = None | ||
self._color_temp = None | ||
|
||
_LOGGER.debug("Init light %s %s", self._device.ip, self._device.mac) |
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 move this to setup_platform
.
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! Can be merged when build passes.
Description:
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#6328
Example entry for
configuration.yaml
(if applicable):Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.