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 basic support for Tradfri switches #17007
Conversation
_LOGGER = logging.getLogger(__name__) | ||
|
||
DEPENDENCIES = ['tradfri'] | ||
PLATFORM_SCHEMA = SWITCH_PLATFORM_SCHEMA |
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.
This isn't needed.
def __init__(self, switch, api, gateway_id): | ||
"""Initialize a switch.""" | ||
self._api = api | ||
self._unique_id = "switch-{}-{}".format(gateway_id, switch.id) |
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.
"switch"
isn't needed. The core will keep track of platform and domain.
cmd = self._switch.observe(callback=self._observe_update, | ||
err_callback=self._async_start_observe, | ||
duration=0) | ||
self.hass.async_add_job(self._api(cmd)) |
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 hass.async_create_task
.
import logging | ||
|
||
from homeassistant.core import callback | ||
from homeassistant.components.switch import ( |
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.
'homeassistant.components.switch.PLATFORM_SCHEMA' imported but unused
Tox passes the unit tests and lint, but return errors when installing deps for pylint and typing. Given that TravisCI passes, this should be ok anyways? |
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.
Should we add tests? There are some tests but not for all existing platforms.
|
||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
"""Load Tradfri switchs based on a config entry.""" |
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.
switches
@callback | ||
def _async_start_observe(self, exc=None): | ||
"""Start observation of switch.""" | ||
# pylint: disable=import-error |
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 do we need to disable this?
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 must admin I borrowed a lot of the code from the Trådfri light-component and this line is in there. That aside, won't lint throw an error when you do an import that's not at the top of a module?
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, we import here since we import something from the requirements library. Try remove the disable.
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 like it worked without the line.
I looked into the tests folder earlier today and it looks like the tests are all not really relating to what the component does, merely how it's setup within Home Assistant. What are the general guidelines here? |
We have excluded these modules from coverage so tests are not required except for config flow. I think it's ok to not add tests for this 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.
Can be merged when build passes.
Description:
IKEA has released new wall switches. Support was added to pytradfri in 5.6.0 and the purpose of this PR is to add support to Home Assistant.
Related issue (if applicable): fixes #
Fixes #16608
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#6392
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
.If the code does not interact with devices: