mitch7391 / homebridge-cmd4-AdvantageAir

Catered shell script to integrate air conditioner control units by Advantage Air into HomeKit using the plug-in homebridge-cmd4.
MIT License
38 stars 5 forks source link

[Pull Request] Run Check Configuration from Command Line #74

Closed uswong closed 1 year ago

uswong commented 1 year ago

name: Check Configuration from Command Line about: Add an improvement to homebridge-cmd4-AdvantageAir. title: "Check Configuration from Command Line" labels: Improvement assignees: mitch7391


Following the success of running ConfigCreator from Command-Line for HOOBS users, Mitch has an idea of making Check Configuration Command-Line friendly as well for HOOBS users and for those users who have no access to Homebridge-ui.

I told Mitch that I would explore the CHECK CONFIGURATION JavaScript to see whether I can implement that to run from Terminal.

Is your pull request related to a problem or a new feature? Please describe:

An improvement.

Describe the solution you'd have implemented:

1. CheckConfig creation:

CHECK CONFIGURATION button will invoke server.js JavaScript as a child process via html to do the "checking" of config.json. Once I have understood the internal working of the server.js, I extracted the main “checking” engine from it and modified some codes around it and in it so that it can be run as a main process from a Terminal using “node.js” rather than a child process called from html. I called this modified JavaScript CheckConfig.js.

The inputs required to this CheckConfig.js are the paths to AdvAir.sh and config.json and the routines looking for those paths have already been coded within ConfigCreator.sh. So I extracted those routines from ConfigCreator.sh and created a new bash script called CheckConfig.sh.

So To check the config.json using Command-Line, all we need to do is to run the bash script CheckConfig.sh which will find the paths and feed those paths into the JavaScript CheckConfig.js to do the exact same checking as the CHECK CONFIGURATION button in Homebridge-ui. The messages are exactly the same too but the messages are delivered to the terminal rather than to the Homebridge-ui.

2. ConfigCreator minor modification

I have also added a prompt to ConfigCreator. The prompt will encourage users to run the CheckConfig following a successful ConfigCreator run. The path to run CheckConfig is provided as well:

Please copy/paste and run the following two commands to check whether the Cmd4 configuration meets all the requirements
check1="/usr/local/lib/node_modules/homebridge-cmd4-advantageair/CheckConfig.sh"
$check1

Do your changes pass local testing:

Additional context:

To run the CheckConfig independently, do the following:

  1. Set the Terminal to home drive, so that there is no permission issue:

    cd
  2. For Homebridge users:

    check1=$(find /usr/local/lib -name CheckConfig.sh 2>&1|grep -v find|grep -v System|grep -v cache|grep node_modules|grep cmd4-advantageair|grep CheckConfig.sh)

    or

    check1=$(find /usr/lib -name CheckConfig.sh 2>&1|grep -v find|grep -v System|grep -v cache|grep node_modules|grep cmd4-advantageair|grep CheckConfig.sh)

    For HOOBS users:

    check1=$(find /var/lib/hoobs -name CheckConfig.sh 2>&1|grep -v find|grep -v System|grep -v cache|grep node_modules|grep cmd4-advantageair|grep CheckConfig.sh)
  3. Check the content of check1

     echo “$check1”
  4. if the response from step 3 is a single file path, then do the following to run the script and ignore the rest of the steps:

     $check1
  5. There is little chance that you will find two file paths in step 3, but if you do, do the following to extract the first path or a path of your choice. To extract the second path, replace 1p in the following command with 2p, and so on:

     check2=$(echo “${check1}”|sed -n 1p)
  6. Check the content of check2

     echo “$check2”
  7. if the response from above is a single file path, then do the following to run the script:

     $check2

The following is a screen shot of running CheckConfig:

image

if a requirement is not meet, the CheckConfig will throw an error in red color as follow: image

Correct the error and run CheckConfig again. Some errors like the example above can be corrected by editing config.json directly. If there is an error on "displayName is defined twice" especially for lights or garage door, you have to change the name of one of them in your AdvantageAir system and re-run ConfigCreator before running CheckConfig again.

A prompt was added to prompt users to run the CheckConfig following a successful run of ConfigCreator:

image

mitch7391 commented 1 year ago

Testing has passed with flying colours on both HOOBS and Homebridge! I really like the added touch of providing the next two commands for the CheckConfig at the end of the ConfigCreator. One small note I have is that you actually do not have to reboot Homebridge/HOOBS to see the new config and for the CheckConfig to use it. Should we still tell the user to reboot Homebridge/HOOBS at this stage, I think we could get away with not having to do it? They really only need to reboot if they are not going to run CheckConfig (to apply the new config and be done) or after they have run the CheckConfig. Curious on your thoughts :)

image

uswong commented 1 year ago

Nice!

They really only need to reboot if they are not going to run CheckConfig (to apply the new config and be done) or after they have run the CheckConfig. Curious on your thoughts :)

You are spot on there! What do you think an appropriate text should be following a successful ConfigCreator run to bring that message across to users?

One suggestion (thinking out loud here): DONE! Restart Homebridge or HOOBS for the created config to take effect or run CheckConfig prior (recommended).

mitch7391 commented 1 year ago

I think that or something similar will suffice :) I’ll edit it myself today and looks like we will be good for the next publish!