-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Read rtl_433_mqtt_hass.py configuration from rtl_433.conf #2841
Open
klattimer
wants to merge
4
commits into
merbanan:master
Choose a base branch
from
klattimer:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aa313f5
Read rtl_433_mqtt_hass.py configuration from rtl_433.conf
klattimer c360190
Find the config file.
klattimer 10e5ea9
New MQTT release requires a callback API version to be specified to a…
klattimer f109051
rtl_433_device_info is a mess and doesn't parse the device string cor…
klattimer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1053,13 +1053,67 @@ def run(): | |
if not args.password and 'MQTT_PASSWORD' in os.environ: | ||
args.password = os.environ['MQTT_PASSWORD'] | ||
|
||
if not args.user or not args.password: | ||
logging.warning("User or password is not set. Check credentials if subscriptions do not return messages.") | ||
|
||
if args.ids: | ||
ids = ', '.join(str(id) for id in args.ids) | ||
logging.info("Only discovering devices with ids: [%s]" % ids) | ||
else: | ||
logging.info("Discovering all devices") | ||
|
||
found_config = False | ||
try: | ||
with open(find_file_in_path(CONFIG_FILENAME, CONFIG_PATHS)) as f: | ||
found = re.findall('^output (.*)$', f.read(), re.MULTILINE) | ||
devices = None | ||
events = None | ||
retain = None | ||
user = None | ||
password = None | ||
host = None | ||
port = None | ||
for find in found: | ||
if "mqtt" not in find: continue | ||
host = re.findall(r'mqtt://(.*?),', find)[0] | ||
devices = re.findall(r'devices=(.*?)(?:,+|$)', find) | ||
if len(devices) > 0: devices = devices[0] | ||
events = re.findall(r'events=(.*?)(?:,+|$)', find) | ||
if len(events) > 0: events = events[0] | ||
retain = re.findall(r'retain=(.*?)(?:,+|$)', find) | ||
if len(retain) > 0: retain = retain[0] | ||
|
||
if '@' in host: | ||
user, password = host.split('@')[0].split(':') | ||
host = host.split('@')[1] | ||
if ':' in host: | ||
host, port = host.split(':') | ||
found_config = True | ||
break | ||
except FileNotFoundError: | ||
logging.warning("Config file not found") | ||
except Exception as e: | ||
logging.exception("Error reading config file") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, be explicit about the file. |
||
|
||
if found_config: | ||
if host: | ||
logging.info(f"Using host {host} from config") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as about, be more explicit about the source, "from config" is a bit ambiguous. |
||
args.host = host | ||
if port: | ||
logging.info(f"Using port {port} from config") | ||
args.port = int(port) | ||
if user: | ||
logging.info(f"Using user {user} from config") | ||
args.user = user | ||
if password: | ||
args.password = password | ||
if retain: | ||
logging.info(f"Using retain {retain} from config") | ||
args.retain = retain | ||
if devices: | ||
logging.info(f"Using device_topic_suffix {devices} from config") | ||
args.device_topic_suffix = devices | ||
if events: | ||
logging.info(f"Using rtl_topic {events} from config") | ||
args.rtl_topic = events | ||
if not args.user or not args.password: | ||
logging.warning("User or password is not set. Check credentials if subscriptions do not return messages.") | ||
|
||
run() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It would be helpful to be less ambiguous about what config file you are talking about in this and the other log messages.
I would explicitly mention that it is rtl_433's config file and/or the path.
Some of the Home Assistant add-ons have their own config files for this script.