eslavnov / pylips

Control Philips TVs (2015+) and Ambilight (+ Hue) through their reverse-engineered API (+ MQTT support!)
MIT License
342 stars 60 forks source link

[FEAT] define ini file path #44

Closed b2un0 closed 4 years ago

b2un0 commented 4 years ago

Is your feature request related to a problem? Please describe. i have two Philips Android TVs and want to monitor them from my Docker Container https://github.com/b2un0/pylips/blob/master/Dockerfile

but i can't define a absolute path of the settings.ini, so i must mount them from outside.

Describe the solution you'd like an new argument to define a path of the settings.ini

Describe alternatives you've considered mount the settings.ini file absolute like the following is not an option for me:

docker run -d \
    --name pylips-70PUS7304 \
    --restart=unless-stopped \
    -v ~/pylips_70PUS7304.ini:/opt/pylips/settings.ini \
     b2un0/pylips:latest

Additional context

i wish i could something like this where pylips_data is an named docker volume which contained the following files:

$ pwd 
/var/lib/docker/volumes/pylips_data
$ tree
└── _data
    ├── 55PUS6551.ini
    └── 70PUS7304.ini

1 directory, 2 files

and i can run both container with the same volume:

docker run -d \
    --name pylips-70PUS7304 \
    --restart=unless-stopped \
    -v pylips_data:/mnt/pylips_data/ \
     --entrypoint "python /opt/pylips/pylips.py --ini /mnt/pylips_data/70PUS7304.ini" \
     b2un0/pylips:latest
docker run -d \
    --name pylips-55PUS6551 \
    --restart=unless-stopped \
    -v pylips_data:/mnt/pylips_data/ \
     --entrypoint "python /opt/pylips/pylips.py --ini /mnt/pylips_data/55PUS6551.ini" \
     b2un0/pylips:latest
b2un0 commented 4 years ago

as an alternative, i would like an option to define mandatory options from ENV Vars:

parser = argparse.ArgumentParser(description="Control Philips TV API (versions 5 and 6)")
parser.add_argument("--host", dest="host", help="TV's ip address", default=os.environ.get('PYLIPS_HOST', None))
parser.add_argument("--user", dest="user", help="Username", default=os.environ.get('PYLIPS_USERNAME', None))
parser.add_argument("--pass", dest="password", help="Password", default=os.environ.get('PYLIPS_PASSWORD', None))
parser.add_argument("--command", help="Command to run", default="")
parser.add_argument("--path", dest="path", help="API's endpoint path")
parser.add_argument("--body", dest="body", help="Body for post requests")
parser.add_argument("--verbose", dest="verbose", help="Display feedback", default=os.environ.get('PYLIPS_VERBOSE', "1"))
parser.add_argument("--apiv", dest="apiv", help="Api version", default=os.environ.get('PYLIPS_APIV', ""))

but in this case, i have no idea how to define the mqtt broker wihtout mounting again the settings.ini from outside..

eslavnov commented 4 years ago

Good suggestion, thanks! I'll add a config path argument some time this weekend!

eslavnov commented 4 years ago

Hey @b2un0,

Terribly sorry for the delay: I had to deal with some personal stuff and had zero time to work on Pylips. I will fix this issue by the end of this week.

Sorry again!

eslavnov commented 4 years ago

Hey, @b2un0!

Better late than never: the new version should support custom config paths, use it like this:

python pylips.py --config '/home/eslavnov/repos/Pylips/some_settings.ini'

I've run some tests and it seems to be working fine, but it could be that I've missed something - please let me know if it works for you. Thanks!

b2un0 commented 4 years ago

thank you, yes it works:

version: '3.5'

volumes:
    data:

services:
    55PUS6551:
        image: b2un0/pylips:latest
        restart: unless-stopped
        network_mode: bridge
        logging:
            driver: "journald"
        volumes:
            - data:/config
        command: "python /opt/pylips/pylips.py --config /config/55PUS6551.ini"
        entrypoint: ""

    70PUS7304:
        image: b2un0/pylips:latest
        restart: unless-stopped
        network_mode: bridge
        logging:
            driver: "journald"
        volumes:
            - data:/config
        command: "python /opt/pylips/pylips.py --config /config/70PUS7304.ini"
        entrypoint: ""

2019-11-29 at 10 16

eslavnov commented 4 years ago

Glad to hear that, thanks!