Improve configuration schema for Geniushub integration#23155
Conversation
| username = hass_config[DOMAIN].get(CONF_USERNAME) | ||
| password = hass_config[DOMAIN].get(CONF_PASSWORD) | ||
| else: | ||
| host = hass_config[DOMAIN].get(CONF_TOKEN) |
There was a problem hiding this comment.
Don't call this host, when it's not a host.
Eg collect the arguments in a tuple and pass the tuple to the class.
There was a problem hiding this comment.
Which do you prefer:
host = token = None
if CONF_HOST in hass_config[DOMAIN]:
host = hass_config[DOMAIN].get(CONF_HOST)
username = hass_config[DOMAIN].get(CONF_USERNAME)
password = hass_config[DOMAIN].get(CONF_PASSWORD)
else:
token = hass_config[DOMAIN].get(CONF_TOKEN)
username = password = None
try:
client = geniushub_data['client'] = GeniusHubClient(
host if host else token, username, password,
session=async_get_clientsession(hass)
)or
if CONF_HOST in hass_config[DOMAIN]:
hub_identifier = hass_config[DOMAIN].get(CONF_HOST)
username = hass_config[DOMAIN].get(CONF_USERNAME)
password = hass_config[DOMAIN].get(CONF_PASSWORD)
else:
hub_identifier = hass_config[DOMAIN].get(CONF_TOKEN)
username = password = None
try:
client = geniushub_data['client'] = GeniusHubClient(
hub_identifier, username, password,
session=async_get_clientsession(hass)
)or
host = hass_config[DOMAIN].get(CONF_HOST)
username = hass_config[DOMAIN].get(CONF_USERNAME)
password = hass_config[DOMAIN].get(CONF_PASSWORD)
token = hass_config[DOMAIN].get(CONF_TOKEN)
try:
client = geniushub_data['client'] = GeniusHubClient(
host if host else token, username, password,
session=async_get_clientsession(hass)
)There was a problem hiding this comment.
Collect the arguments in a tuple.
if blabla:
args = arg1, arg2, etc
else:
args = (arg4, )
client = class(*args, session=session)There was a problem hiding this comment.
Oh, I see - but it would a tuple of 1 (hub_id), the rest are kwargs/dict. I don't see what would be gained:
def __init__(self, hub_id, username=None, password=None, session=None, debug=False)So how about:
kwargs = dict(hass_config[DOMAIN])
if CONF_HOST in kwargs:
args = (kwargs.pop(CONF_HOST), )
else:
args = (kwargs.pop(CONF_TOKEN), )
try:
client = geniushub_data['client'] = GeniusHubClient(
*args, **kwargs, session=async_get_clientsession(hass)
)There was a problem hiding this comment.
We gain that we don't confuse ourselves by naming a variable something which it isn't.
There was a problem hiding this comment.
👍 In addition, I think it's kind of elegant - you get a two-for-one from voluptuous.
MartinHjelmare
left a comment
There was a problem hiding this comment.
Can be merged when last comment is addressed.
Codecov Report
@@ Coverage Diff @@
## dev #23155 +/- ##
==========================================
+ Coverage 94.19% 94.2% +<.01%
==========================================
Files 453 453
Lines 36915 36915
==========================================
+ Hits 34773 34775 +2
+ Misses 2142 2140 -2
Continue to review full report at Codecov.
|
2 similar comments
Codecov Report
@@ Coverage Diff @@
## dev #23155 +/- ##
==========================================
+ Coverage 94.19% 94.2% +<.01%
==========================================
Files 453 453
Lines 36915 36915
==========================================
+ Hits 34773 34775 +2
+ Misses 2142 2140 -2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## dev #23155 +/- ##
==========================================
+ Coverage 94.19% 94.2% +<.01%
==========================================
Files 453 453
Lines 36915 36915
==========================================
+ Hits 34773 34775 +2
+ Misses 2142 2140 -2
Continue to review full report at Codecov.
|
|
The first PR for this integration is already in 0.92 beta, so tagging this for 0.92 too. |
|
Woot! Merged! Thanks @MartinHjelmare 💐 @GeoffAtHome 🥇 |
* configuration for hub tokens are now separate from host addresses/credentials * small change to docstring * use *args **kwargs
Breaking Change:
Nil, original PR, #21598, is still in dev
Description:
See config section, below.
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#8815
Example entry for
configuration.yaml(if applicable):As per @MartinHjelmare request, config is now be either of:
... or ...
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:
requirementsin the manifest (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: