n8henrie / fauxmo

Emulated Belkin WeMo devices that work with the Amazon Echo
https://n8henrie.com/2016/02/fauxmo-home-automation-with-the-amazon-echo-raspberry-pi-and-homeassistant/
Other
376 stars 78 forks source link

Windows 8.1 #109

Closed mocallins closed 3 years ago

mocallins commented 3 years ago

Hi Nate.

Any reason this shouldn't work on a Windows pc ?

n8henrie commented 3 years ago

Hi!

I can't say based on personal experience -- I have no Windows machines -- but it is pure Python stdlib with no other dependencies, which would make it seem likely to work.

A quick search of the issues shows several people trying to use Windows, and it seems like it was working for some of them.

I referenced a "workaround for Windows" in the code; git blame leads me to a commit referencing this issue: https://github.com/n8henrie/fauxmo/issues/21

If you try it out, please report back!

mocallins commented 3 years ago

Thanks for the response Nate. Clued me in that it should work, so i went and was checking things on my windows machine. Was beginning to make me wonder about whether i was running network via wireless or my ethernet link, and that did not change, when i tried to run fauxmo.exe So then i started checking how i was running fauxmo.exe and it turns out, using an environment variable is not working correctly, for some reason. I was trying to run as follows: (in directory "C:\Python38\Scripts", which is where pip installed it) fauxmo.exe -c %userprofile%\config.json -vv ( %userprofile% points to home directory),  WASN'T working.Changed it to hard coded home directory, and is running as expected. So thanks for the feedback. My whole reason for trying this is because i want to run some Windows based actions via Alexa i.e. like when whatever time i happen to get up, and i tell Alexa "i'm up" launch a couple of things on my  computer.Not having much luck getting to run those sommands on Windows. Thanks again.

On Wednesday, September 1, 2021, 10:02:08 AM CDT, Nathan Henrie ***@***.***> wrote:  

Hi!

I can't say based on personal experience -- I have no Windows machines -- but it is pure Python stdlib with no other dependencies, which would make it seem likely to work.

A quick search of the issues shows several people trying to use Windows, and it seems like it was working for some of them.

I referenced a "workaround for Windows" in the code; git blame leads me to a commit referencing this issue: #21

If you try it out, please report back!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

mocallins commented 3 years ago

Well i don't know what i've done to not have this working. However i don't believe its any reason to open a trouble ticket. I have had it discover some of the definitions at 1 point, and don't know what i would have changed , but now it does not discover anything. Similar to what I had running on the Raspberry pi.

I'm going to go ahead and close this as an issue. Thanks for the assistance.

mocallins commented 3 years ago

Hi Nate. Any way we can make the commandlineplugin more robust ?

Having valid command line syntax is a killer, wow.

I can now get Alexa to regularly run discovery and find the devices emulated on a Windows pc, and it all really has to do with proper escaping a windows command, with "\", aaaarrrggghhh

I'm still having a problem with the 'c:\Program Files' syntax. Any suggestions / examples, lol

n8henrie commented 3 years ago

Any way we can make the commandlineplugin more robust ?

Can you elaborate?

it all really has to do with proper escaping a windows command, with "\"

Are you using raw strings? e.g. r"c:\Program Files"

mocallins commented 3 years ago

I triewd the raw string delimiter a while back, and I thought i remember it hickup over that, but can definatel try again.

As for making it more robust, just not requireing all the escaped backslashing. I mean really this is 2021 and we still have to get strings of characters, exactly right?

n8henrie commented 3 years ago

As for making it more robust, just not requireing all the escaped backslashing.

That definitely sounds like a Python problem and not a Fauxmo problem ;)

Raw strings should be helpful here.

mocallins commented 3 years ago

Yea it hickups.

    config = json.loads(config_path.read_text())
  File "c:\python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "c:\python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "c:\python38\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 17 column 23 (char 410)

config.json

        {
            "name": "youtube",
            "port": 49921,
            "on_cmd": r"C:\\Program\\ Files\\Mozilla Firefox\\firefox.exe youtube.com",
            "off_cmd": "echo youtube off",
            "use_fake_state": true
        }
mocallins commented 3 years ago

Is there a way to trigger discovery when we start fauxmo, without have to say "Alexa discover" ? I know when there a certain skills enabled, Alexa just tells us we havbe a new device.

mocallins commented 3 years ago

Holy crap, i got it.

        "on_cmd": "\"C:\\Program Files\\Mozilla Firefox\\firefox.exe\" youtube.com",

uugghhh

mocallins commented 3 years ago

As for making it more robust, just not requireing all the escaped backslashing.

That definitely sounds like a Python problem and not a Fauxmo problem ;)

Raw strings should be helpful here.

Yea, i'm for sure its not a fauxmo problem. lower level library, i just thought maybe you had an idea for workaround.

n8henrie commented 3 years ago

Looking at this a bit, I think it's more a problem of escaping in json; in json, all of the backslashes need to be escaped by a backslash / doubled. I don't think python raw strings will be helpful.

n8henrie commented 3 years ago

Here's one other thought -- make yourself a little python helper, where you can use raw-strings to make things easier (notice the r preceding "C:\\), then have it output what you need to put in your json config.

#!/usr/bin/env python3

import json

val = {"foo": "bar", "testpath": r"C:\\baz\qux"}

def main():
    print(json.dumps(val, indent=4))

if __name__ == "__main__":
    main()

Example output:

$ python3 make_json.py 
{
    "foo": "bar",
    "testpath": "C:\\\\baz\\qux"
}

I think I'll go ahead and close this issue if that's okay!

mocallins commented 3 years ago

I hadn't thought about a helper, i was just curious if you wanted to change it to a python dictionary. Syntax is so similar, i don't think anybody would have trouble, then it can be raw and you could perform an internal native substitition, so it would be correct, on whatever platform.

At least i think python has a path.native(), i'm pretty sure it does, all i can think right now is i KNOW TCL does, i doubt python would be left out of that capability.

mocallins commented 3 years ago

and i just looked real quick there are 3 path related os.path methods os.path.(realpath|normpath|abspath)