Supereg / homebridge-http-switch

Powerful http switch for Homebridge: https://github.com/homebridge/homebridge
ISC License
222 stars 37 forks source link

Regex or Statuspattern bug? Full details and tests inside. Please help. #105

Closed mrfatboy closed 2 years ago

mrfatboy commented 2 years ago

Happy New Year.

I'm having a status pattern issue. No matter what the status pattern I use the switch is always defined as ON. If I turn it OFF it goes back ON in 3 seconds (because of my pulling interval).

I can see in the Homebridge logs that it is requesting the statusurl every 3 seconds like I have set. Clearly the Standby is in the body of the response. Please refer to this link regex tester to see the Response body or see text below.

I even found this yamaha receiver github wiki with examples. Just so happens I had the exact same thing :) https://github-wiki-see.page/m/Supereg/homebridge-http-switch/wiki/Community-supplied-examples

I have use this regex tester https://regex101.com/r/PcsbOD/1

What am I doing wrong or is this a bug? Thanks much.

My config is:

        {
            "accessory": "HTTP-SWITCH",
            "name": "Yamaha TEST",
            "switchType": "stateful",
            "onUrl": {
                "method": "POST",
                "headers": {
                    "Content-Type": "text/xml"
                },
                "url": "http://192.168.1.20:80/YamahaRemoteControl/ctrl",
                "body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><YAMAHA_AV cmd=\"PUT\"><Main_Zone><Power_Control><Power>On</Power></Power_Control></Main_Zone></YAMAHA_AV>"
            },
            "offUrl": {
                "method": "POST",
                "headers": {
                    "Content-Type": "text/xml"
                },
                "url": "http://192.168.1.20:80/YamahaRemoteControl/ctrl",
                "body": "<?xml version= \"1.0\" encoding=\"UTF-8\"?><YAMAHA_AV cmd=\"PUT\"><Main_Zone><Power_Control><Power>Standby</Power></Power_Control></Main_Zone></YAMAHA_AV>"
            },
            "statusUrl": {
                "method": "POST",
                "headers": {
                    "Content-Type": "text/xml"
                },
                "url": "http://192.168.1.20:80/YamahaRemoteControl/ctrl",
                "body": "<?xml version=\"1.0\" encoding=\"utf-8\"?><YAMAHA_AV cmd=\"GET\"><Main_Zone><Basic_Status>GetParam</Basic_Status></Main_Zone></YAMAHA_AV>"
            },
            "statuspattern": "<Power>On</Power>",
            "debug": true,
            "pullInterval": 3000
        },

Response Body

<YAMAHA_AV rsp="GET" RC="0">
    <Main_Zone>
        <Basic_Status>
            <Power_Control>
                <Power>Standby</Power>
                <Zone_B_Power_Info>Standby</Zone_B_Power_Info>
                <Sleep>Off</Sleep>
            </Power_Control>
            <Volume>
                <Lvl>
                    <Val>-305</Val>
                    <Exp>1</Exp>
                    <Unit>dB</Unit>
                </Lvl>
                <Mute>Off</Mute>
                <Subwoofer_Trim>
                    <Val>0</Val>
                    <Exp>1</Exp>
                    <Unit>dB</Unit>
                </Subwoofer_Trim>
                <Scale>0-97</Scale>
                <Zone_B>
                    <Feature_Availability>Ready</Feature_Availability>
                    <Interlock>Off</Interlock>
                    <Lvl>
                        <Val>-250</Val>
                        <Exp>1</Exp>
                        <Unit>dB</Unit>
                    </Lvl>
                    <Mute>On</Mute>
                </Zone_B>
            </Volume>
            <Input>
                <Input_Sel>HDMI1</Input_Sel>
                <Input_Sel_Item_Info>
                    <Param>HDMI1</Param>
                    <RW>RW</RW>
                    <Title>Directv  </Title>
                    <Icon>
                        <On>/YamahaRemoteControl/Icons/icon004.png</On>
                        <Off></Off>
                    </Icon>
                    <Src_Name></Src_Name>
                    <Src_Number>1</Src_Number>
                </Input_Sel_Item_Info>
            </Input>
            <Surround>
                <Program_Sel>
                    <Current>
                        <Straight>Off</Straight>
                        <Enhancer>Off</Enhancer>
                        <Sound_Program>7ch Stereo</Sound_Program>
                    </Current>
                </Program_Sel>
                <_3D_Cinema_DSP>Auto</_3D_Cinema_DSP>
            </Surround>
            <Sound_Video>
                <Tone>
                    <Bass>
                        <Val>0</Val>
                        <Exp>1</Exp>
                        <Unit>dB</Unit>
                    </Bass>
                    <Treble>
                        <Val>0</Val>
                        <Exp>1</Exp>
                        <Unit>dB</Unit>
                    </Treble>
                </Tone>
                <Direct>
                    <Mode>Off</Mode>
                </Direct>
                <HDMI>
                    <Standby_Through_Info>On</Standby_Through_Info>
                    <Output>
                        <OUT_1>On</OUT_1>
                    </Output>
                </HDMI>
                <Extra_Bass>Auto</Extra_Bass>
                <Adaptive_DRC>Off</Adaptive_DRC>
            </Sound_Video>
            <Speaker_Preout>
                <Speaker_AB>
                    <Speaker_A>On</Speaker_A>
                    <Speaker_B>On</Speaker_B>
                </Speaker_AB>
            </Speaker_Preout>
        </Basic_Status>
    </Main_Zone>
</YAMAHA_AV>
mrfatboy commented 2 years ago

Another facepalm moment, I just noticed it should be "statusPattern" non "statuspattern".

All solved. Works great.