Add support to ignore selected gateways#72
Conversation
syssi
left a comment
There was a problem hiding this comment.
I would prefer to ignore unconfigured gateways per default and handle just configured ones.
|
I also think so, but considering that if this is done, existing users will not be available if they are not configured. Of course, you can also consider setting the default value to true in home-assistant/core#14428 |
|
You are right! All discovered gateways are used at the moment. There is no indicator for a unconfigured gateway (the security key isn't required). Your approach is fine! |
| try: | ||
| ip_address = socket.gethostbyname(host) | ||
| if _disabled: | ||
| _LOGGER.info("Xiaomi Gateway %s is disabled in the configuration", sid) |
There was a problem hiding this comment.
"disabled by configuration"
| self.gateways[ip_add] = XiaomiGateway(ip_add, port, sid, gateway_key, self._socket, | ||
| resp["proto_version"] if "proto_version" in resp else None) | ||
| if disabled: | ||
| _LOGGER.info("Xiaomi Gateway %s is disabled in the configuration", |
| host = gateway.get('host') | ||
| port = gateway.get('port') | ||
| sid = gateway.get('sid') | ||
| key = gateway.get('key') |
There was a problem hiding this comment.
I wouldn't move this line in this case. It's None if no key is available.
There was a problem hiding this comment.
Yes, I removed it just to pass the lint check, because there are too many local variables and this variable is only used in one place. So I'll call it directly on the method argument.
|
@Danielhiversen Do you agree with these changes? |
Fix problem of crash when getting the key when there is no gateway.
Support disabled gateway.