Skip to content
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

Merged
merged 5 commits into from Sep 25, 2018
Merged

Conversation

jedmeng
Copy link
Contributor

@jedmeng jedmeng commented Sep 21, 2018

Description:

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#6328

Example entry for configuration.yaml (if applicable):

light:
  - platform: opple
    name: LIGHT_NAME
    host: IP_ADDRESS

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

Copy link
Member

@MartinHjelmare MartinHjelmare left a 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):
Copy link
Member

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')
Copy link
Member

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.

Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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:
Copy link
Member

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.

@MartinHjelmare
Copy link
Member

The config section in the PR description is not accurate.

return

if not self.available:
_LOGGER.debug("Light %s is offline", self._device.ip)
Copy link
Member

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.

Copy link
Contributor Author

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']
Copy link
Member

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']
Copy link
Member

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)
Copy link
Member

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.

Copy link
Member

@MartinHjelmare MartinHjelmare left a 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.

@balloob balloob merged commit 8e31168 into home-assistant:dev Sep 25, 2018
@ghost ghost removed the in progress label Sep 25, 2018
@balloob balloob mentioned this pull request Oct 12, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants