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] Multiple Aircon Systems and Ability to Flip Open/Close #50

Closed uswong closed 2 years ago

uswong commented 2 years ago

name: Pull Request about: add an improvement to homebridge-cmd4-AdvantageAir. title: "Added support for multiple aircon systems and ability to flip open/close" labels: pull-request assignees: mitch7391


Added support for multiple aircon systems and added the ability to flip the garage's or gate's open/close

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

Describe the solution you'd have implemented:

  1. Created a variable $ac for various aircon systems (ac1, ac2, ac3, ac4, ac5) which can be specified with a constant in state_cmd_suffix
  2. Created a constant flip which can be specified in state-cmd-suffix of garage/gate accessory to enable the flipping of open/close display on Homekit

Do your changes pass local testing:

Additional context:

  1. Sample config for multiple aircon system If you have more than one aircon systems, all the accessories pertaining to the aircon system other than the first one (ac1) has to have the aircon system (ac2 or ac3 or ac4 or ac5) specified as a constant in state_cmd_suffix.

Below is a sample config of accessory Thermostat for aircon system ac2 :

        {
            "type": "Thermostat",
            "displayName": "Aircon",
            "currentHeatingCoolingState": "OFF",
            "targetHeatingCoolingState": "OFF",
            "currentTemperature": 24,
            "targetTemperature": 24,
            "temperatureDisplayUnits": "CELSIUS",
            "name": "Aircon",
            "manufacturer": "Advantage Air Australia",
            "model": "e-zone",
            "serialNumber": "Daikin e-zone",
            "queue": "A",
            "polling": [
                {
                    "characteristic": "currentHeatingCoolingState"
                },
                {
                    "characteristic": "targetHeatingCoolingState"
                },
                {
                    "characteristic": "currentTemperature"
                },
                {
                    "characteristic": "targetTemperature"
                }
            ],
            "state_cmd": "'/usr/local/lib/node_modules/homebridge-cmd4-advantageair/AdvAir.sh'",
            "state_cmd_suffix": "ac2 ${IP}",
            "linkedTypes": [
                {
                    "type": "Fan",
                    "displayName": "Fan Speed",
                    "on": "TRUE",
                    "rotationSpeed": 100,
                    "name": "Fan Speed",
                    "manufacturer": "Advantage Air Australia",
                    "model": "e-zone",
                    "serialNumber": "Daikin e-zone",
                    "queue": "A",
                    "polling": [
                        {
                            "characteristic": "on"
                        },
                        {
                            "characteristic": "rotationSpeed"
                        }
                    ],
                    "state_cmd": "'/usr/local/lib/node_modules/homebridge-cmd4-advantageair/AdvAir.sh'",
                    "state_cmd_suffix": "ac2 ${IP} fanSpeed"
                }
            ]
        }
  1. sample config to flip the garage or gate open/close If you need to flip your garage's or gate's open/close, all you need to do is to have the constant flip in your garage or gate accessory's state_cmd_sufix:
        {
            "type": "GarageDoorOpener",
            "displayName": "Garage Door",
            "obstructionDetected": "FALSE",
            "currentDoorState": 1,
            "targetDoorState": 1,
            "name": "Garage Door",
            "manufacturer": "Advantage Air Australia",
            "model": "e-zone",
            "serialNumber": "Daikin e-zone",
            "queue": "A",
            "polling": [
                {
                    "characteristic": "currentDoorState"
                },
                {
                    "characteristic": "targetDoorState"
                }
            ],
            "state_cmd": "'/usr/local/lib/node_modules/homebridge-cmd4-advantageair/AdvAir.sh'",
            "state_cmd_suffix": "flip 'thing:Garage' ${IP}"
        }
mitch7391 commented 2 years ago

Hey Ung Sing, I can see you had added 'ac1' in the script as the default; which was going to be my first question off the bat. Nice job on this as it will not affect current users with only one aircon and not require any changes from them :p everything looks great!

uswong commented 2 years ago

I can see you had added 'ac1' in the script as the default;

yes, no change whatsoever required for existing users with single aircon system.

mitch7391 commented 2 years ago

Hey Ung Sing; first day off out of night shifts and finally testing this locally. I notice just about all of my unit tests fail now:

31 tests, 25 failures, 2 skipped

Is this the same for you?

Also another question, the flip constant can go after 'thing:Garage' and not affect anything yeah? Just looks neater and thought I would check before I update the Wiki.

uswong commented 2 years ago

Hi Mitch, you need to update your unit tests to JohnT's latest version. I have included it in my PR under the /test subdirectory.

and yes the flip can be anywhere.

mitch7391 commented 2 years ago

As in this PR just approved or a coming one? As that is what I have tested haha...

uswong commented 2 years ago

It should be in the one just approved. Let me double check whether that is the correct one.

uswong commented 2 years ago

Yes, that is the one.

The red highlighted one is an extra one of my own testing. Tt will fail on that one and you can ignore that.

image

mitch7391 commented 2 years ago

Hmmm well I have 25 failures, not one or a couple lol

pi@homebridge:/tmp/homebridge-cmd4-AdvantageAir $ npm run test

> homebridge-cmd4-advantageair@3.3.0-beta.5 pretest
> if [ ! -d 'node_modules' ];then printf ' test is only done in a development environment
> ';exit 1; fi

> homebridge-cmd4-advantageair@3.3.0-beta.5 test
> npm run allBats && npm run testjs && npm run check && npm run lint

> homebridge-cmd4-advantageair@3.3.0-beta.5 allBats
> bats test/*.bats

 ✗ AdvAir ( ezone inline ) Test PassOn1 Get Brightness z01
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetBrightness.bats, line 55)
     `assert_equal "$status" 0' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone inline ) Test PassOn1 Get Brightness z03
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetBrightness.bats, line 63)
     `assert_equal "$status" 0' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone inline ) Test PassOn5 Get CurrentHeatingCoolingState
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetCurrentHeatingCoolingState.bats, line 31)
     `assert_equal "$status" "$e_status" ]' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone        ) Test PassOn1 Get CurrentHeatingCoolingState
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    from function `_common_compareAgainstEzone' in file ./test/setup, line 77,
    in test file test/GetCurrentHeatingCoolingState.bats, line 39)
     `_common_compareAgainstEzone Get Blah CurrentHeatingCoolingState TEST_ON' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone inline ) Test PassOn5 Get CurrentTemperature
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetCurrentTemperature.bats, line 38)
     `assert_equal "$status" "$e_status"' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone inline ) Test PassOn1 Get CurrentTemperature z01
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetCurrentTemperature.bats, line 54)
     `assert_equal "$status" "$e_status"' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( zones inline ) Test PassOn1 Get CurrentTemperature z01
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetCurrentTemperature.bats, line 69)
     `assert_equal "$status" "$e_status"' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( zones inline ) Test PassOn1 Get CurrentTemperature z03
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetCurrentTemperature.bats, line 83)
     `assert_equal "$status" "$e_status"' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone inline ) Test PassOn1 Get CurrentTemperature with NoSensor Data (creating new myAirConstants
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetCurrentTemperature.bats, line 103)
     `assert_equal "$status" "$e_status"' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone inline ) Test PassOn1 Get CurrentTemperature with NoSensor Data (with cached myAirConstants
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetCurrentTemperature.bats, line 116)
     `assert_equal "$status" 0' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone inline ) Test PassOn1 Get CurrentTemperature with NoSensor Data
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetNoSensors.bats, line 29)
     `assert_equal "${lines[1]}" "25.4"' failed

   -- values do not equal --
   expected : 25.4
   actual   : 0
   --

 ✗ AdvAir ( ezone inline ) Test PassOn5 Get On
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetOn.bats, line 31)
     `assert_equal "$status" "$e_status" ]' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone        ) Test PassOn1 Get On
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    from function `_common_compareAgainstEzone' in file ./test/setup, line 77,
    in test file test/GetOn.bats, line 42)
     `_common_compareAgainstEzone Get Fan On TEST_ON' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( zones        ) Test PassOn1 Get On z01
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    from function `_common_compareAgainstZones' in file ./test/setup, line 55,
    in test file test/GetOn.bats, line 50)
     `_common_compareAgainstZones Get Fan On z01 TEST_ON' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( zones inline ) Test PassOn5 Get StatusLowBattery z01
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetStatusLowBattery.bats, line 32)
     `assert_equal "$status" "$z_status" ]' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( zones        ) Test PassOn1 Get StatusLowBattery z01
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    from function `_common_compareAgainstZones' in file ./test/setup, line 55,
    in test file test/GetStatusLowBattery.bats, line 41)
     `_common_compareAgainstZones Get Blah StatusLowBattery z01 TEST_ON' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone inline ) Test PassOn5 Get TargetHeatingCoolingState
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetTargetHeatingCoolingState.bats, line 31)
     `assert_equal "$status" "$e_status" ]' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone        ) Test PassOn1 Get TargetHeatingCoolingState
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    from function `_common_compareAgainstEzone' in file ./test/setup, line 77,
    in test file test/GetTargetHeatingCoolingState.bats, line 40)
     `_common_compareAgainstEzone Get Blah TargetHeatingCoolingState TEST_ON' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone inline ) Test PassOn5 Get TargetTemperature
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/GetTargetTemperature.bats, line 32)
     `assert_equal "$status" "$e_status" ]' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✗ AdvAir ( ezone        ) Test PassOn1 Get TargetTemperature
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    from function `_common_compareAgainstEzone' in file ./test/setup, line 77,
    in test file test/GetTargetTemperature.bats, line 42)
     `_common_compareAgainstEzone Get Blah TargetTemperature TEST_ON' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 ✓ AdvAir ( ezone inline ) Get PassOn1 TemperatureDisplayUnits ( inline )
 ✓ AdvAir ( ezone       ) Get PassOn1 TemperatureDisplayUnits ( inline )
 ✗ AdvAir ( ezone inline ) Test Invalid Option 'BLAH'
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/InvalidOption.bats, line 21)
     `assert_equal "$status" "1"' failed

   -- values do not equal --
   expected : 1
   actual   : 127
   --

 ✗ AdvAir ( ezone inline ) Test IP PassOn1
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/InvalidOption.bats, line 34)
     `assert_equal "$status" "0"' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 - AdvAir ( ezone / zone ) Test ../homebridge.log.txt (skipped: Skipping test. No ../homebridge.log.txt from /tmp/homebridge-cmd4-AdvantageAir/test)
 ✗ AdvAir ( ezone inline ) Test PassOn5 Set On 1
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/SetOn.bats, line 25)
     `assert_equal "${lines[0]}" "Setting url: http://192.168.0.173:2025/setAircon?json={ac1:{info:{state:on,mode:vent}}}"' failed

   -- values do not equal --
   expected : Setting url: http://192.168.0.173:2025/setAircon?json={ac1:{info:{state:on,mode:vent}}}
   actual   : /tmp/homebridge-cmd4-AdvantageAir/node_modules/bats/lib/bats-core/test_functions.bash: line 37: ./compare/AdvAir.sh: No such file or directory
   --

 ✗ AdvAir ( zones inline ) Test PassOn1 Set On 1 z01
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/SetOn.bats, line 39)
     `assert_equal "${lines[0]}" "${e_lines[0]}"' failed

   -- values do not equal --
   expected : Setting url: http://192.168.0.173:2025/setAircon?json={ac1:{zones:{z01:{state:open}}}}
   actual   : /tmp/homebridge-cmd4-AdvantageAir/node_modules/bats/lib/bats-core/test_functions.bash: line 37: ./compare/AdvAir.sh: No such file or directory
   --

 ✗ AdvAir ( ezone inline ) Test PassOn1 Set TargetHeatingCoolingState 1
   (from function `assert_equal' in file node_modules/bats-assert/src/assert.bash, line 91,
    in test file test/SetTargetHeatingCoolingState.bats, line 23)
     `assert_equal "$status" "$e_status" ]' failed

   -- values do not equal --
   expected : 0
   actual   : 127
   --

 - Sample Test (How to Skip) (skipped: This test is skipped just to show that skippping can be done.)
 ✓ Sample Test Check Status of run command
 ✓ Sample Test Check stdout of command

31 tests, 25 failures, 2 skipped
uswong commented 2 years ago

that's a bit strange. Mine all passed.

Please check GetBrightness.bats to see if it looks like this or not.

image

mitch7391 commented 2 years ago

Looks the same to me:

# Understanding these test cases
#
# What we are trying to do is compare the execution of AdvAir.sh with either
# the previous ezone/zones scripts or some expected output. In that way
# you can rerun these tests after any change to AdvAir.sh and gaurantee the
# result in production without having to try every possible scenario.

# Unit tests have a setup function before and a teardown function after each
# test. These can be ignored if you are just trying to figure out what
# went wrong. Remember that what we are testing is BASH shell commands you can
# execute them also from the command line.

# For example:
#    cd test
#    ln -s ./testData/dataPassOn5 ./data
#    ./compare/AdvAir.sh Get Blah Brightness z01 192.168.50.99 TEST_ON
#
# Results to stdout:
#     Try 0
#     Try 1
#     Try 2
#     Try 3
#     Try 4
#     100
#
#
# Note: TEST_ON is so that we do not actually talk to the real device,
#       instead jq parses the given testData.
#
# Then afterwards:
#    $status      - is the result of the ./compare/AdvAir.sh command
#    ${lines[0]}  - is an array of text from the ./compare/AdvAir.sh command
#    assert_equal "${lines[0]}" "Try 0"  - compares the output in line 0.

setup()
{
   load './test/setup'
   _common_setup
}

teardown()
{
   _common_teardown
}

@test "AdvAir ( ezone inline ) Test PassOn1 Get Brightness z01" {
   # We symbolically link the directory of the test we want to use.
   ln -s ./testData/dataPassOn1 ./data
   # The original scripts do not have this function, so you can only
   # test against known data
   run ./compare/AdvAir.sh Get Blah Brightness z01 192.168.50.99 TEST_ON
   assert_equal "$status" 0
   assert_equal "${lines[0]}" "Try 0"
   assert_equal "${lines[1]}" "100"
}

@test "AdvAir ( ezone inline ) Test PassOn1 Get Brightness z03" {
   ln -s ./testData/dataPassOn1 ./data
   run ./compare/AdvAir.sh Get Blah Brightness z03 192.168.50.99 TEST_ON
   assert_equal "$status" 0
   assert_equal "${lines[0]}" "Try 0"
   assert_equal "${lines[1]}" "85"
}
mitch7391 commented 2 years ago

Oh, I wonder... You have changed all the IP addresses to your own? I think they all used to be based on mine haha...

uswong commented 2 years ago

I did not change any IP address, that was JohnT's version. I only done a very minor eidts on the SetOn.bats and SetTargetHeatingCoolingTemperature.bats to reflect that I do not have a Get before a Set on those.

My IP is 192.168.0.31.

mitch7391 commented 2 years ago

All good, I will take a look if the IP address change fixes them for me; otherwise I am not terribly concerned at this point as it will not affect users.