Merge pull request #60 from hjelev/dev
update readme.md and device description displayed in hass
This commit is contained in:
10
README.md
10
README.md
@@ -214,12 +214,16 @@ Create a cron entry like this (you might need to update the path in the cron ent
|
|||||||
```
|
```
|
||||||
## How to update
|
## How to update
|
||||||
|
|
||||||
Navigate to the folder where Rapsberry Pi MQTT Monitor is installed and pull the git repository:
|
Remote updates via Home Assistant are now available.
|
||||||
|
|
||||||
|
To use these you need to have the script running as a service. (the installer now supports this)
|
||||||
|
|
||||||
|
Manual update:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git pull
|
cd rpi-mqtt-monitor
|
||||||
|
python3 src/update.py
|
||||||
```
|
```
|
||||||
* Note that sometimes you might need to add new variables to our src/config.py file, so make sure you check the example file and update your config.py file accordingly.
|
|
||||||
|
|
||||||
## Home Assistant Integration
|
## Home Assistant Integration
|
||||||
|
|
||||||
|
|||||||
@@ -146,18 +146,11 @@ def get_manufacturer():
|
|||||||
|
|
||||||
|
|
||||||
def check_git_update(script_dir):
|
def check_git_update(script_dir):
|
||||||
full_cmd = "git -C {} remote update && git -C {} status -uno".format(script_dir, script_dir)
|
if config.version == update.check_git_version_remote(script_dir):
|
||||||
try:
|
|
||||||
git_update = subprocess.Popen(full_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0].decode("utf-8")
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
print("Error updating git repository:", e.output)
|
|
||||||
|
|
||||||
if any(s in git_update for s in ('Your branch is up to date', 'Your branch is up-to-date', 'Votre branche est à jour')):
|
|
||||||
git_update = {
|
git_update = {
|
||||||
"installed_ver": config.version,
|
"installed_ver": config.version,
|
||||||
"new_ver": config.version,
|
"new_ver": config.version,
|
||||||
}
|
}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
git_update = {
|
git_update = {
|
||||||
"installed_ver": config.version,
|
"installed_ver": config.version,
|
||||||
@@ -193,9 +186,9 @@ def print_measured_values( cpu_load=0, cpu_temp=0, used_space=0, voltage=0, sys_
|
|||||||
print(" Version: " + config.version)
|
print(" Version: " + config.version)
|
||||||
print("")
|
print("")
|
||||||
print(":: Device Information")
|
print(":: Device Information")
|
||||||
print(" Model Name: " + check_model_name().strip())
|
print(" Model Name: " + check_model_name())
|
||||||
print(" Manufacturer: " + get_manufacturer().strip())
|
print(" Manufacturer: " + get_manufacturer())
|
||||||
print(" OS: " + get_os().strip())
|
print(" OS: " + get_os())
|
||||||
print(" Hostname: " + hostname)
|
print(" Hostname: " + hostname)
|
||||||
print(" IP Address: " + get_network_ip())
|
print(" IP Address: " + get_network_ip())
|
||||||
if args.service:
|
if args.service:
|
||||||
@@ -228,10 +221,11 @@ def config_json(what_config):
|
|||||||
"unit_of_measurement": "",
|
"unit_of_measurement": "",
|
||||||
"device": {
|
"device": {
|
||||||
"identifiers": [hostname],
|
"identifiers": [hostname],
|
||||||
"manufacturer": manufacturer,
|
"manufacturer": 'github.com/hjelev',
|
||||||
"model": model_name,
|
"model": 'RPi MQTT Monitor ' + config.version,
|
||||||
"name": hostname,
|
"name": hostname,
|
||||||
"sw_version": config.version,
|
"sw_version": os,
|
||||||
|
"hw_version": model_name + " by " + manufacturer,
|
||||||
"configuration_url": "https://github.com/hjelev/rpi-mqtt-monitor"
|
"configuration_url": "https://github.com/hjelev/rpi-mqtt-monitor"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,7 +300,7 @@ def config_json(what_config):
|
|||||||
version = check_git_version(script_dir).strip()
|
version = check_git_version(script_dir).strip()
|
||||||
data["icon"] = "mdi:update"
|
data["icon"] = "mdi:update"
|
||||||
data["name"] = "RPi MQTT Monitor Update"
|
data["name"] = "RPi MQTT Monitor Update"
|
||||||
data["title"] = "RPi MQTT Monitor v" + version
|
data["title"] = "Version"
|
||||||
data["state_topic"] = config.mqtt_topic_prefix + "/" + hostname + "/" + "git_update"
|
data["state_topic"] = config.mqtt_topic_prefix + "/" + hostname + "/" + "git_update"
|
||||||
data["value_template"] = "{{ {'installed_version': value_json.installed_ver, 'latest_version': value_json.new_ver } | to_json }}"
|
data["value_template"] = "{{ {'installed_version': value_json.installed_ver, 'latest_version': value_json.new_ver } | to_json }}"
|
||||||
data["device_class"] = "firmware"
|
data["device_class"] = "firmware"
|
||||||
@@ -486,7 +480,7 @@ def parse_arguments():
|
|||||||
exit()
|
exit()
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
installed_version = check_git_version(script_dir).strip()
|
installed_version = config.version
|
||||||
latest_versino = update.check_git_version_remote(script_dir).strip()
|
latest_versino = update.check_git_version_remote(script_dir).strip()
|
||||||
print("Installed version: " + installed_version)
|
print("Installed version: " + installed_version)
|
||||||
print("Latest version: " + latest_versino)
|
print("Latest version: " + latest_versino)
|
||||||
|
|||||||
@@ -18,9 +18,19 @@ def update_config(current_config, example_config):
|
|||||||
missing_assignments = {var: value for var, value in example_assignments.items() if var not in current_assignments}
|
missing_assignments = {var: value for var, value in example_assignments.items() if var not in current_assignments}
|
||||||
|
|
||||||
if missing_assignments:
|
if missing_assignments:
|
||||||
|
with open(current_config, 'ab+') as f: # Open the file in binary mode
|
||||||
|
f.seek(-1, os.SEEK_END) # Move the cursor to the last character
|
||||||
|
last_char = f.read(1) # Read the last character
|
||||||
|
|
||||||
|
# If the last character is not a newline, write a newline
|
||||||
|
if last_char != b'\n':
|
||||||
|
with open(current_config, 'a') as f: # Open the file in text mode
|
||||||
|
f.write('\n')
|
||||||
|
|
||||||
|
# Write the missing assignments
|
||||||
with open(current_config, 'a') as f:
|
with open(current_config, 'a') as f:
|
||||||
for var, value in missing_assignments.items():
|
for var, value in missing_assignments.items():
|
||||||
f.write('\n{} = {!r}'.format(var, value))
|
f.write('{} = {!r}\n'.format(var, value))
|
||||||
|
|
||||||
|
|
||||||
def display_config_differences(current_config, example_config, display=True):
|
def display_config_differences(current_config, example_config, display=True):
|
||||||
|
|||||||
Reference in New Issue
Block a user