home-assistant-libs / pytradfri

IKEA Trådfri/Tradfri API. Control and observe your lights from Python. Examples available. On pypi. Sans-io.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for Motion Sensor passthrough

mrtolkien opened this issue · comments

commented

The Tradfri Gateway has gotten an update recently and both Motion Sensors and Shortcut buttons can now be used in HomeKit, as a passthrough:
https://www.reddit.com/r/tradfri/comments/lqgf3a/using_tradfri_motion_sensors_with_homekit/

You need to unpair the Sensor first then re-pair it, and not add it to a room or link to a light.

This means the data is now fully accessible through the gateway and should be usable in home assistant as a standard motion sensor!

I am not familiar at all with the Tradfri structure and gateway system, but I would love to help add support in any way possible as I'd rather control automation through HA than HomeKit.

Thanks a lot for the help!

That is indeed good news.

Making it available in HA is a 2 step procedure, first this library needs to support it, which is relatively simple. I have just added a PR that will allow dumping the communication to/from the the gateway, the dump will be used to add tests.

The second step is to add support in the HA tradfri integration, which is a bit more work.

A good first step would be, to run examples/debug_info.py (see README), and dump the devices (provided you have a motion sensor installed). If you save it as a file and pass it to me, I can have a look at it.

I hope you’re right but I don’t have high hopes 😊 I’m looking into this every now and then (this summer was the last time I checked) to no avail. I planned taking a look tonight but was out of batteries in my sensor.

What I’ve seen in the past is that the sensor is there but doesn’t report anything relevant on its endpoint.

commented

I don't own a Motion Sensor but I'll try and grab one today.

It's by far the cheapest motion detector readily buyable in Japan so I'll try to make it work!

The output looks like it's always done for my sensor :(

{
  '3': {'0': 'IKEA of Sweden',
          '1': 'TRADFRI motion sensor',
          '2': '',
          '3': '1.2.214',
          '6': 3,
          '7': 4548,
          '9': 100},
    '3300': [{'9003': 0}],
    '5750': 4,
    '9001': 'TRADFRI motion sensor',
    '9002': 1634990177,
    '9003': 65555,
    '9019': 1,
    '9020': 1634990184,
    '9054': 0
}
commented

Do you know what each field means? Could one of them be the last timestamp where the sensor was triggered? I have seen some sensors that worked that way.

I got a sensor myself today, will take a look at the values sent by the API tomorrow. It is indeed working through HomeKit.

Yes, the meaning of each value is in the motion sensor is faily well-documented:
https://github.com/home-assistant-libs/pytradfri/blob/master/pytradfri/const.py

commented

@janiversen, I did run the debug script but there are 6 possible outputs. This is the one that's relevant to the motion sensor:

    {
        "3": {
            "0": "IKEA of Sweden",
            "1": "TRADFRI motion sensor",
            "2": "",
            "3": "2.0.022",
            "6": 3,
            "7": 4552,
            "9": 87
        },
        "3300": [
            {
                "9003": 0
            }
        ],
        "5750": 4,
        "9001": "TRADFRI motion sensor",
        "9002": 1634978358,
        "9003": 65544,
        "9019": 1,
        "9020": 1635065676,
        "9054": 0
    },

@ggravlingen it seems new Motion Sensors are on version 2.x (field 3:3) which might be what allows this new behaviour?

commented

I have tried dumping the data from the sensor for the past few hours, and I indeed can't seem to see anything appear in the gateway API that would pass the value of the sensor. The gateway.get_endpoints function also does not show anything more than a single endpoint for the sensor.

At the same time, the integration works perfectly in HomeKit, and the sensor is properly seen as detecting motion when I enter a room.

How could the gateway be passing this information to HomeKit?

The gateway communicates with the app through the coap-protocol. I believe Homekit uses a separate protocol?

commented

I'm not finding exactly how it works here:
https://developer.apple.com/documentation/homekit

What is see there is that:

You don’t create characteristic instances. Instead, an accessory manufacturer incorporates them into a device, which publishes them to you through the characteristics array of an HMService instance.

So this is where Ikea Tradfri exposes this piece information. I wonder if we can plug to it somehow?

Then it's probably not available. Doesn't https://www.home-assistant.io/ have a Homekit integration that could be used for this?

HA offers both the possibility to connect to a homekit system or act as a homekit server.

commented

I will try to setup the HomeKit Controller integration tomorrow and use the Tradfri motion sensors through it.

If this works, we can take a look at their code and maybe integrate some of it to this library for the feature? I feel like supporting the motion sensor in standalone mode is pretty huge as it's one of the cheapest and most widely distributed motion detector out there.

We can't implement the homekit protocol in the pytradfri library. Any features we consume from the gateway will need to be exposed in the coap protocol.

Yes, this has been the idea of the library since it’s inception.

@mrtolkien if you want a standalone mode, there are plenty of homekit libraries on github, if you prefer it integrated just use HA.

I’ll close this issue for now. Let’s open a new one if Ikea decides to expose the data through their Coap-lib.

commented

I feel like it's a bit unfortunate to see this package as glued to a particular protocol if another one offers more features. At the same time, I really with Ikea simply exposed this data through the current API indeed, as it would make it much simpler and usable with other automation systems.

It is my understanding that now this kind of info is exposed through the Gateway. anyone could test or dump info?

@koliploik can you please elaborate? Where have you seen this?

Amazon Alexa is able to access this kind of info (not using HomeKit) so the gateway someway release this info, probably through the CoAP communication. In your understanding is the CoAP info accessible? An alternative to this approach could be to read the info of a light that turns on, if the communication to turn on a light contains the ID of the remote control that triggered the light it is maybe possible to deduce if a motion sensor was triggered, don't know if this is remotely possible or not (obviously this have limitations). Can someone with more knowledge than me explain if tap into CoAp info is feasible or not? Thanks

Are you familiar with VS Code and Docker? If so, it's quite easy to extract the information. I'll advise how when I know how experienced you are.

Docker yes I know enough, VS Code unfortunately not that much.

OK, assuming you have docker on your system:

  • Make sure Docker is running
  • Download and install VS Code
  • Install the extension ms-vscode-remote.remote-containers (Dev Containers) in VS code.
  • Clone this repo and open it in VS Code
  • You should see this box when opening. Click "Reopen in container" and wait for the environment to load.
image
  • You should now see the command line looking something like this: (.venv) vscode ➜ /workspaces/pytradfri (master) $. Here, you want to type python3 -i -m pytradfri 192.168.20.11, and replace the IP address with the address to your gateway.
  • Type dump_devices() or dump_all() and see if you can find the motion sensor in there.

Thanks for your instructions, unfortunately I'm not able to open the repo in docker. Between 26-29 seconds while VS code is preparing the VM I get an error "Exit code 1". I've tried almost anything my mind could think of...

  • downgraded the "Dev containers" to older versions
  • in the code I can see pip require to be updated, after updating it I still get same message on the log.
  • restarted WSL
  • checked WSL version used and is correctly 2.
  • Docker engine is running, is killed the log stop in just 2 secs asking for docker.

Unfortunately all this without any luck.
Here the log:

[23 ms] Dev Containers 0.299.0 in VS Code 1.80.1 (74f6148eb9ea00507ec113ec51c489d6ffb4b771).
[22 ms] Start: Resolving Remote
[47 ms] Setting up container for folder or workspace: c:\temp\git3\pytradfri
[47 ms] Start: Run: wsl -l -v
[140 ms] Start: Run: wsl -d docker-desktop-data -e /bin/sh -c echo ~
[293 ms] Could not connect to WSL.
[293 ms] Command failed: wsl -d docker-desktop-data -e /bin/sh -c echo ~
[293 ms] 
[293 ms] <3>WSL (20) ERROR: CreateProcessEntryCommon:370: getpwuid(0) failed 2
<3>WSL (20) ERROR: CreateProcessEntryCommon:374: getpwuid(0) failed 2
<3>WSL (20) ERROR: CreateProcessEntryCommon:577: execvpe /bin/sh failed 2
<3>WSL (20) ERROR: CreateProcessEntryCommon:586: Create process not expected to return
[294 ms] Start: Check Docker is running
[294 ms] Start: Run: docker version --format {{.Server.APIVersion}}
[444 ms] Server API version: 1.43
[444 ms] Start: Run: docker volume ls -q
[599 ms] Start: Run: docker ps -q -a --filter label=vsch.local.folder=c:\temp\git3\pytradfri --filter label=vsch.quality=stable
[770 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=c:\temp\git3\pytradfri --filter label=devcontainer.config_file=c:\temp\git3\pytradfri\.devcontainer\devcontainer.json
[908 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=c:\temp\git3\pytradfri
[1063 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=c:\temp\git3\pytradfri
[1203 ms] Start: Run: C:\Users\luxbr\AppData\Local\Programs\Microsoft VS Code\Code.exe --ms-enable-electron-run-as-node c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js read-configuration --workspace-folder c:\temp\git3\pytradfri --id-label devcontainer.local_folder=c:\temp\git3\pytradfri --id-label devcontainer.config_file=c:\temp\git3\pytradfri\.devcontainer\devcontainer.json --log-level debug --log-format json --config c:\temp\git3\pytradfri\.devcontainer\devcontainer.json --mount-workspace-git-root true
[1450 ms] @devcontainers/cli 0.46.0. Node.js v16.17.1. win32 10.0.19045 x64.
[1450 ms] Start: Run: git rev-parse --show-cdup
[1529 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=c:\temp\git3\pytradfri --filter label=devcontainer.config_file=c:\temp\git3\pytradfri\.devcontainer\devcontainer.json
[1680 ms] Start: Run: C:\Users\luxbr\AppData\Local\Programs\Microsoft VS Code\Code.exe --ms-enable-electron-run-as-node c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js up --user-data-folder c:\Users\luxbr\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --container-session-data-folder /tmp/devcontainers-eee7ffe3-9338-422b-be6e-ed26ac8812671690139442321 --workspace-folder c:\temp\git3\pytradfri --workspace-mount-consistency cached --id-label devcontainer.local_folder=c:\temp\git3\pytradfri --id-label devcontainer.config_file=c:\temp\git3\pytradfri\.devcontainer\devcontainer.json --log-level debug --log-format json --config c:\temp\git3\pytradfri\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[1930 ms] @devcontainers/cli 0.46.0. Node.js v16.17.1. win32 10.0.19045 x64.
[1930 ms] Start: Run: docker buildx version
[2514 ms] github.com/docker/buildx v0.11.0 687feca9e8dcd1534ac4c026bc4db5a49de0dd6e
[2514 ms] 
[2514 ms] Start: Resolving Remote
[2517 ms] Start: Run: git rev-parse --show-cdup
[2759 ms] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=c:\temp\git3\pytradfri --filter label=devcontainer.config_file=c:\temp\git3\pytradfri\.devcontainer\devcontainer.json
[2906 ms] Start: Run: docker inspect --type image mcr.microsoft.com/vscode/devcontainers/python:0-3.10-bullseye
[3077 ms] local container features stored at: c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\node_modules\vscode-dev-containers\container-features
[3079 ms] Start: Run: tar --no-same-owner -x -f -
[3134 ms] Start: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f C:\Users\luxbr\AppData\Local\Temp\devcontainercli\container-features\0.46.0-1690139445989\Dockerfile-with-features -t vsc-pytradfri-f1d4cd4f7b750925df7367e0958693c0cdd3de4db976468b7f006a44e2ae9862 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label c:\temp\git3\pytradfri

[+] Building 29.5s (8/8) FINISHED                                docker:default
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load build definition from Dockerfile-with-features         0.0s
 => => transferring dockerfile: 2.88kB                                     0.0s
 => [internal] load metadata for mcr.microsoft.com/vscode/devcontainers/p  0.0s
 => [internal] load build context                                          0.2s
 => => transferring context: 1.53MB                                        0.2s
 => CACHED [dev_container_auto_added_stage_label 1/4] FROM mcr.microsoft.  0.0s
 => [dev_container_auto_added_stage_label 2/4] COPY . /usr/src/app         0.1s
 => [dev_container_auto_added_stage_label 3/4] WORKDIR /usr/src/app        0.0s
 => ERROR [dev_container_auto_added_stage_label 4/4] RUN sudo python3 -m  29.1s
------
 > [dev_container_auto_added_stage_label 4/4] RUN sudo python3 -m venv /opt/.ven
v &&     sudo chown -R vscode:vscode /opt/.venv &&     . /opt/.venv/bin/activate
 &&     python3 -m pip install --upgrade setuptools wheel Cython &&     python3
-m pip install -r /usr/src/app/requirements.txt &&     python3 -m pip install -r
 /usr/src/app/requirements_test.txt &&     sudo /usr/src/app//script/install-coa
p-client.sh:
3.112 Requirement already satisfied: setuptools in /opt/.venv/lib/python3.10/sit
e-packages (65.5.0)
3.465 Collecting setuptools
3.636   Downloading setuptools-68.0.0-py3-none-any.whl (804 kB)
3.882      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 804.0/804.0 kB 3.4 MB/s eta 0
:00:00
3.952 Collecting wheel
3.984   Downloading wheel-0.41.0-py3-none-any.whl (64 kB)
4.000      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.7/64.7 kB 4.3 MB/s eta 0:
00:00
4.384 Collecting Cython
4.427   Downloading Cython-3.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014
_x86_64.whl (3.6 MB)
5.173      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.6/3.6 MB 4.8 MB/s eta 0:00
:00
5.269 Installing collected packages: wheel, setuptools, Cython
5.309   Attempting uninstall: setuptools
5.310     Found existing installation: setuptools 65.5.0
5.357     Uninstalling setuptools-65.5.0:
5.366       Successfully uninstalled setuptools-65.5.0
6.178 Successfully installed Cython-3.0.0 setuptools-68.0.0 wheel-0.41.0
6.331
6.331 [notice] A new release of pip is available: 23.0.1 -> 23.2.1
6.331 [notice] To update, run: pip install --upgrade pip
6.794 Collecting aiocoap==0.4.7
6.912   Downloading aiocoap-0.4.7-py3-none-any.whl (208 kB)
7.001      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 208.4/208.4 kB 2.3 MB/s eta 0
:00:00
7.062 Collecting DTLSSocket==0.1.16
7.101   Downloading DTLSSocket-0.1.16.tar.gz (156 kB)
7.140      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 156.6/156.6 kB 3.9 MB/s eta 0
:00:00
7.160   Installing build dependencies: started
9.741   Installing build dependencies: finished with status 'done'
9.743   Getting requirements to build wheel: started
9.880   Getting requirements to build wheel: finished with status 'done'
9.883   Preparing metadata (pyproject.toml): started
10.06   Preparing metadata (pyproject.toml): finished with status 'done'
10.31 Collecting pydantic==1.10.9
10.35   Downloading pydantic-1.10.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2
014_x86_64.whl (3.1 MB)
11.28      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.1/3.1 MB 3.3 MB/s eta 0:00
:00
11.60 Collecting Cython<3
11.61   Using cached Cython-0.29.36-cp310-cp310-manylinux_2_17_x86_64.manylinux2
014_x86_64.manylinux_2_24_x86_64.whl (1.9 MB)
11.67 Collecting typing-extensions>=4.2.0
11.70   Downloading typing_extensions-4.7.1-py3-none-any.whl (33 kB)
11.72 Building wheels for collected packages: DTLSSocket
11.72   Building wheel for DTLSSocket (pyproject.toml): started
16.73   Building wheel for DTLSSocket (pyproject.toml): finished with status 'do
ne'
16.73   Created wheel for DTLSSocket: filename=DTLSSocket-0.1.16-cp310-cp310-lin
ux_x86_64.whl size=401916 sha256=eb0939a78c49556e12a7783dd13dee51f59a56a5eaa9ac4
a36f034e953a0868e
16.73   Stored in directory: /home/vscode/.cache/pip/wheels/fc/d5/05/ca73b5e6b87
7e56f9bb85cc845acd599b895cf4c0cb6b533c1
16.74 Successfully built DTLSSocket
16.79 Installing collected packages: typing-extensions, Cython, aiocoap, pydanti
c, DTLSSocket
16.81   Attempting uninstall: Cython
16.81     Found existing installation: Cython 3.0.0
16.84     Uninstalling Cython-3.0.0:
16.85       Successfully uninstalled Cython-3.0.0
17.50 Successfully installed Cython-0.29.36 DTLSSocket-0.1.16 aiocoap-0.4.7 pyda
ntic-1.10.9 typing-extensions-4.7.1
17.51
17.51 [notice] A new release of pip is available: 23.0.1 -> 23.2.1
17.51 [notice] To update, run: pip install --upgrade pip
18.03 Collecting black==23.7.0
18.18   Downloading black-23.7.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014
_x86_64.whl (1.7 MB)
18.56      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 4.5 MB/s eta 0:00
:00
19.02 Collecting coverage==7.2.7
19.06   Downloading coverage-7.2.7-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x
86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (228 kB)
19.09      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 228.7/228.7 kB 9.0 MB/s eta 0
:00:00
19.24 Collecting mypy==1.4.1
19.30   Downloading mypy-1.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x
86_64.whl (12.0 MB)
21.49      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 12.0/12.0 MB 5.4 MB/s eta 0:
00:00
21.61 Collecting pre-commit==3.3.3
21.65   Downloading pre_commit-3.3.3-py2.py3-none-any.whl (202 kB)
21.69      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 202.8/202.8 kB 5.1 MB/s eta 0
:00:00
21.77 Collecting pylint==2.17.4
21.82   Downloading pylint-2.17.4-py3-none-any.whl (536 kB)
21.91      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 536.6/536.6 kB 6.4 MB/s eta 0
:00:00
21.96 Collecting pylint_strict_informational==0.1
22.01   Downloading pylint_strict_informational-0.1-py2.py3-none-any.whl (3.0 kB
)
22.10 Collecting pytest==7.4.0
22.13   Downloading pytest-7.4.0-py3-none-any.whl (323 kB)
22.19      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 323.6/323.6 kB 6.5 MB/s eta 0
:00:00
22.24 Collecting pytest-asyncio==0.21.1
22.28   Downloading pytest_asyncio-0.21.1-py3-none-any.whl (13 kB)
22.35 Collecting pytest-cov==4.1.0
22.38   Downloading pytest_cov-4.1.0-py3-none-any.whl (21 kB)
22.44 Collecting pytest-timeout==2.1.0
22.48   Downloading pytest_timeout-2.1.0-py3-none-any.whl (12 kB)
22.54 Collecting pathspec>=0.9.0
22.58   Downloading pathspec-0.11.1-py3-none-any.whl (29 kB)
22.64 Collecting tomli>=1.1.0
22.67   Downloading tomli-2.0.1-py3-none-any.whl (12 kB)
22.72 Collecting mypy-extensions>=0.4.3
22.76   Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)
22.82 Collecting click>=8.0.0
22.85   Downloading click-8.1.6-py3-none-any.whl (97 kB)
22.87      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 kB 9.3 MB/s eta 0:
00:00
22.93 Collecting packaging>=22.0
22.96   Downloading packaging-23.1-py3-none-any.whl (48 kB)
22.97      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 48.9/48.9 kB 7.6 MB/s eta 0:
00:00
23.03 Collecting platformdirs>=2
23.08   Downloading platformdirs-3.9.1-py3-none-any.whl (16 kB)
23.10 Requirement already satisfied: typing-extensions>=4.1.0 in /opt/.venv/lib/
python3.10/site-packages (from mypy==1.4.1->-r /usr/src/app/requirements_test.tx
t (line 3)) (4.7.1)
23.21 Collecting virtualenv>=20.10.0
23.25   Downloading virtualenv-20.24.1-py3-none-any.whl (3.0 MB)
23.75      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.0/3.0 MB 5.9 MB/s eta 0:00
:00
23.86 Collecting pyyaml>=5.1
23.92   Downloading PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014
_x86_64.whl (705 kB)
24.06      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 705.5/705.5 kB 5.3 MB/s eta 0
:00:00
24.18 Collecting identify>=1.0.0
24.24   Downloading identify-2.5.26-py2.py3-none-any.whl (98 kB)
24.26      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 98.8/98.8 kB 5.6 MB/s eta 0:
00:00
24.31 Collecting cfgv>=2.0.0
24.36   Downloading cfgv-3.3.1-py2.py3-none-any.whl (7.3 kB)
24.42 Collecting nodeenv>=0.11.1
24.46   Downloading nodeenv-1.8.0-py2.py3-none-any.whl (22 kB)
24.54 Collecting dill>=0.2
24.58   Downloading dill-0.3.7-py3-none-any.whl (115 kB)
24.60      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 115.3/115.3 kB 6.6 MB/s eta 0
:00:00
24.66 Collecting mccabe<0.8,>=0.6
24.69   Downloading mccabe-0.7.0-py2.py3-none-any.whl (7.3 kB)
24.77 Collecting tomlkit>=0.10.1
24.80   Downloading tomlkit-0.11.8-py3-none-any.whl (35 kB)
24.92 Collecting astroid<=2.17.0-dev0,>=2.15.4
24.96   Downloading astroid-2.15.6-py3-none-any.whl (278 kB)
25.01      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 278.3/278.3 kB 7.2 MB/s eta 0
:00:00
25.11 Collecting isort<6,>=4.2.5
25.14   Downloading isort-5.12.0-py3-none-any.whl (91 kB)
25.16      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 91.2/91.2 kB 5.6 MB/s eta 0:
00:00
25.23 Collecting iniconfig
25.26   Downloading iniconfig-2.0.0-py3-none-any.whl (5.9 kB)
25.32 Collecting pluggy<2.0,>=0.12
25.36   Downloading pluggy-1.2.0-py3-none-any.whl (17 kB)
25.42 Collecting exceptiongroup>=1.0.0rc8
25.46   Downloading exceptiongroup-1.1.2-py3-none-any.whl (14 kB)
25.64 Collecting lazy-object-proxy>=1.4.0
25.68   Downloading lazy_object_proxy-1.9.0-cp310-cp310-manylinux_2_5_x86_64.man
ylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (63 kB)
25.70      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 63.3/63.3 kB 3.3 MB/s eta 0:
00:00
25.86 Collecting wrapt<2,>=1.11
25.91   Downloading wrapt-1.15.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86
_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (78 kB)
25.93      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 78.4/78.4 kB 8.2 MB/s eta 0:
00:00
25.96 Requirement already satisfied: setuptools in /opt/.venv/lib/python3.10/sit
e-packages (from nodeenv>=0.11.1->pre-commit==3.3.3->-r /usr/src/app/requirement
s_test.txt (line 4)) (68.0.0)
26.09 Collecting filelock<4,>=3.12
26.12   Downloading filelock-3.12.2-py3-none-any.whl (10 kB)
26.17 Collecting distlib<1,>=0.3.6
26.21   Downloading distlib-0.3.7-py2.py3-none-any.whl (468 kB)
26.30      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 468.9/468.9 kB 5.0 MB/s eta 0
:00:00
26.52 Installing collected packages: distlib, wrapt, tomlkit, tomli, pyyaml, plu
ggy, platformdirs, pathspec, packaging, nodeenv, mypy-extensions, mccabe, lazy-o
bject-proxy, isort, iniconfig, identify, filelock, exceptiongroup, dill, coverag
e, click, cfgv, virtualenv, pytest, mypy, black, astroid, pytest-timeout, pytest
-cov, pytest-asyncio, pylint, pre-commit, pylint_strict_informational
28.75 Successfully installed astroid-2.15.6 black-23.7.0 cfgv-3.3.1 click-8.1.6
coverage-7.2.7 dill-0.3.7 distlib-0.3.7 exceptiongroup-1.1.2 filelock-3.12.2 ide
ntify-2.5.26 iniconfig-2.0.0 isort-5.12.0 lazy-object-proxy-1.9.0 mccabe-0.7.0 m
ypy-1.4.1 mypy-extensions-1.0.0 nodeenv-1.8.0 packaging-23.1 pathspec-0.11.1 pla
tformdirs-3.9.1 pluggy-1.2.0 pre-commit-3.3.3 pylint-2.17.4 pylint_strict_inform
ational-0.1 pytest-7.4.0 pytest-asyncio-0.21.1 pytest-cov-4.1.0 pytest-timeout-2
.1.0 pyyaml-6.0.1 tomli-2.0.1 tomlkit-0.11.8 virtualenv-20.24.1 wrapt-1.15.0
28.76
28.76 [notice] A new release of pip is available: 23.0.1 -> 23.2.1
28.76 [notice] To update, run: pip install --upgrade pip
28.91 sudo: unable to execute /usr/src/app//script/install-coap-client.sh: No su
ch file or directory
------
Dockerfile-with-features:17
--------------------
  16 |
  17 | >>> RUN sudo python3 -m venv $VIRTUAL_ENV && \
  18 | >>>     sudo chown -R $LOCAL_USER:$LOCAL_USER ${VIRTUAL_ENV} && \
  19 | >>>     . $VIRTUAL_ENV/bin/activate && \
  20 | >>>     python3 -m pip install --upgrade setuptools wheel Cython && \
  21 | >>>     python3 -m pip install -r $FILE_LOCATION/requirements.txt && \
  22 | >>>     python3 -m pip install -r $FILE_LOCATION/requirements_test.txt &&
 \
  23 | >>>     sudo $FILE_LOCATION//script/install-coap-client.sh
  24 |
--------------------
ERROR: failed to solve: process "/bin/sh -c sudo python3 -m venv $VIRTUAL_ENV &&
     sudo chown -R $LOCAL_USER:$LOCAL_USER ${VIRTUAL_ENV} &&     . $VIRTUAL_ENV/
bin/activate &&     python3 -m pip install --upgrade setuptools wheel Cython &&
    python3 -m pip install -r $FILE_LOCATION/requirements.txt &&     python3 -m
pip install -r $FILE_LOCATION/requirements_test.txt &&     sudo $FILE_LOCATION//
script/install-coap-client.sh" did not complete successfully: exit code: 1
[33497 ms] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f C:\Users\luxbr\AppData\Local\Temp\devcontainercli\container-features\0.46.0-1690139445989\Dockerfile-with-features -t vsc-pytradfri-f1d4cd4f7b750925df7367e0958693c0cdd3de4db976468b7f006a44e2ae9862 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label c:\temp\git3\pytradfri
[33497 ms]     at Ute (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2008:1698)
[33497 ms]     at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
[33497 ms]     at async fC (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2007:1691)
[33497 ms]     at async n3 (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2007:610)
[33498 ms]     at async rre (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2024:3660)
[33498 ms]     at async Yf (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2024:4775)
[33498 ms]     at async Dne (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2156:12193)
[33498 ms]     at async Sne (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2156:11934)
[33506 ms] Exit code 1
[33509 ms] Command failed: C:\Users\luxbr\AppData\Local\Programs\Microsoft VS Code\Code.exe --ms-enable-electron-run-as-node c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js up --user-data-folder c:\Users\luxbr\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --container-session-data-folder /tmp/devcontainers-eee7ffe3-9338-422b-be6e-ed26ac8812671690139442321 --workspace-folder c:\temp\git3\pytradfri --workspace-mount-consistency cached --id-label devcontainer.local_folder=c:\temp\git3\pytradfri --id-label devcontainer.config_file=c:\temp\git3\pytradfri\.devcontainer\devcontainer.json --log-level debug --log-format json --config c:\temp\git3\pytradfri\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[33509 ms] Exit code 1

if you have any advice on how to get it working please let me know.

That's odd, it works on my Mac. The error is in the last line of the Dockerfile.dev. Try this code and see if you at least can get the dev container up and running (I've removed the last command).

ARG VARIANT=3.10-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

ENV VIRTUAL_ENV=/opt/.venv
ENV FILE_LOCATION "/usr/src/app"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV LOCAL_USER="vscode"

USER 1000

COPY . $FILE_LOCATION

WORKDIR $FILE_LOCATION

RUN sudo python3 -m venv $VIRTUAL_ENV && \
    sudo chown -R $LOCAL_USER:$LOCAL_USER ${VIRTUAL_ENV} && \
    . $VIRTUAL_ENV/bin/activate && \
    python3 -m pip install --upgrade setuptools wheel Cython && \
    python3 -m pip install -r $FILE_LOCATION/requirements.txt && \
    python3 -m pip install -r $FILE_LOCATION/requirements_test.txt

So without the last line in the Dockerfile.dev it is able to build the image and run it but still has errors along the way:

[...]
Running the postCreateCommand from devcontainer.json...

[39946 ms] Start: Run in container: /bin/sh -c script/setup
[39974 ms] [09:27:39] Installing extension 'dbaeumer.vscode-eslint'...
[39976 ms] [09:27:39] Getting Manifest... dbaeumer.vscode-eslint
[40136 ms] [09:27:39] Installing extension 'ms-python.vscode-pylance'...
[09:27:39] Getting Manifest... ms-python.vscode-pylance
[40146 ms] [09:27:40] Installing extension 'esbenp.prettier-vscode'...
[09:27:40] Getting Manifest... esbenp.prettier-vscode
[40164 ms] [09:27:40] Installing extension 'ms-python.python'...
[40165 ms] [09:27:40] Getting Manifest... ms-python.python
[40188 ms] [09:27:40] Installing extension: dbaeumer.vscode-eslint
[40299 ms] [09:27:40] Installing extension: esbenp.prettier-vscode
[40329 ms] [09:27:40] Installing extension: ms-python.vscode-pylance
[40372 ms] [09:27:40] Installing extension: ms-python.python
/bin/sh: 1: script/setup: not found
[40537 ms] postCreateCommand failed with exit code 127. Skipping any further user-provided commands.
[40540 ms] Error: Command failed: /bin/sh -c script/setup
[40540 ms]     at T8 (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:1780:130)
[40541 ms]     at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
[40541 ms]     at async G0 (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:1772:4434)
[40541 ms]     at async H0 (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:1772:3779)
[40541 ms]     at async W0 (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:1772:2983)
[40542 ms]     at async Nne (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2156:31301)
[40542 ms]     at async Lne (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2156:28556)
[40545 ms] [09:27:40] Installing extension 'visualstudioexptteam.vscodeintellicode'...
[40546 ms] [09:27:40] Getting Manifest... visualstudioexptteam.vscodeintellicode
[40560 ms] Exit code 1
[40561 ms] Command failed: C:\Users\luxbr\AppData\Local\Programs\Microsoft VS Code\Code.exe --ms-enable-electron-run-as-node c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js run-user-commands --user-data-folder c:\Users\luxbr\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --container-session-data-folder /tmp/devcontainers-ac2a955d-ced0-4624-8fae-b0ebf68fc0571690190819257 --workspace-folder c:\temp\git5\pytradfri --id-label devcontainer.local_folder=c:\temp\git5\pytradfri --id-label devcontainer.config_file=c:\temp\git5\pytradfri\.devcontainer\devcontainer.json --container-id 9b58781e112513a5da828dd19b75f73ccf3501836041b41b7ed9b7ec21761552 --log-level debug --log-format json --config c:\temp\git5\pytradfri\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --skip-non-blocking-commands false --prebuild false --stop-for-personalization true --remote-env REMOTE_CONTAINERS_IPC=/tmp/vscode-remote-containers-ipc-2cb78579-6f31-4ab0-9862-05463a7e4715.sock --remote-env SSH_AUTH_SOCK=/tmp/vscode-ssh-auth-2cb78579-6f31-4ab0-9862-05463a7e4715.sock --remote-env REMOTE_CONTAINERS=true --mount-workspace-git-root true --terminal-columns 209 --terminal-rows 26 --dotfiles-target-path ~/dotfiles
[40760 ms] [09:27:40] Installing extension: visualstudioexptteam.vscodeintellicode
[41106 ms] [09:27:40] Getting Manifest... visualstudioexptteam.intellicode-api-usage-examples
[41288 ms] [09:27:41] Installing extension: visualstudioexptteam.intellicode-api-usage-examples visualstudioexptteam.vscodeintellicode
[41551 ms] [09:27:41] Getting Manifest... ms-python.vscode-pylance
[41823 ms] [09:27:41] Waiting for already requested installing extension ms-python.vscode-pylance ms-python.python
[42879 ms] [09:27:42] Extension signature is verified: esbenp.prettier-vscode
[42880 ms] [09:27:42] Extension signature is verified: dbaeumer.vscode-eslint
[...]

I was able to run the install-coap-client.sh with this dev file:

ARG VARIANT=3.10-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

ENV VIRTUAL_ENV=/opt/.venv
ENV FILE_LOCATION "/usr/src/app"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV LOCAL_USER="vscode"

COPY . $FILE_LOCATION

WORKDIR $FILE_LOCATION

RUN chmod +x /usr/src/app/script/install-coap-client.sh

USER 1000

RUN sudo python3 -m venv $VIRTUAL_ENV && \
    sudo chown -R $LOCAL_USER:$LOCAL_USER ${VIRTUAL_ENV} && \
    . $VIRTUAL_ENV/bin/activate && \
    python3 -m pip install --upgrade setuptools wheel Cython && \
    python3 -m pip install -r $FILE_LOCATION/requirements.txt && \
    python3 -m pip install -r $FILE_LOCATION/requirements_test.txt

but getting error later /bin/sh: 1: script/setup: not found [40537 ms] postCreateCommand failed with exit code 127. Skipping any further user-provided commands.

in the new terminal, after docker is running (in both cases: either without last line from dev file or with my modified dev file) the result is the same:

source /opt/.venv/bin/activate
vscode ➜ /workspaces/pytradfri $ source /opt/.venv/bin/activate
(.venv) vscode ➜ /workspaces/pytradfri $ python3 -i -m pytradfri 192.168.178.xxx
DEBUG:pytradfri.util:JSON file not found: tradfri_standalone_psk.conf
Please provide the 'Security Code' on the back of your Tradfri gateway: xxx
DEBUG:pytradfri.util:JSON file not found: tradfri_standalone_psk.conf
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.178.xxx post ['15011', '9063']: {'9090': 'e16b02d045d24a10b0119ea4f4b0fa9c'}
Traceback (most recent call last):
  File "/workspaces/pytradfri/pytradfri/__main__.py", line 55, in <module>
    identity = conf[org_args.host].get("identity")
KeyError: '192.168.178.xxx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/workspaces/pytradfri/pytradfri/__main__.py", line 63, in <module>
    psk = api_factory.generate_psk(org_args.key)
  File "/workspaces/pytradfri/pytradfri/api/libcoap_api.py", line 220, in generate_psk
    self._psk = self.request(Gateway().generate_psk(existing_psk_id))
  File "/workspaces/pytradfri/pytradfri/api/libcoap_api.py", line 142, in request
    return self._execute(api_commands, timeout=timeout)
  File "/workspaces/pytradfri/pytradfri/api/libcoap_api.py", line 117, in _execute
    return_value = subprocess.check_output(command, **kwargs)
  File "/usr/local/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/lib/python3.10/subprocess.py", line 503, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/local/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.10/subprocess.py", line 1863, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'coap-client'

I will have to try to run the whole thing from a different machine (unfortunately no Mac, only a second Win machine) as I'm not able to find the issue with this one.

So without the last line in the Dockerfile.dev it is able to build the image and run it but still has errors along the way:

[...]
Running the postCreateCommand from devcontainer.json...

[39946 ms] Start: Run in container: /bin/sh -c script/setup
[39974 ms] [09:27:39] Installing extension 'dbaeumer.vscode-eslint'...
[39976 ms] [09:27:39] Getting Manifest... dbaeumer.vscode-eslint
[40136 ms] [09:27:39] Installing extension 'ms-python.vscode-pylance'...
[09:27:39] Getting Manifest... ms-python.vscode-pylance
[40146 ms] [09:27:40] Installing extension 'esbenp.prettier-vscode'...
[09:27:40] Getting Manifest... esbenp.prettier-vscode
[40164 ms] [09:27:40] Installing extension 'ms-python.python'...
[40165 ms] [09:27:40] Getting Manifest... ms-python.python
[40188 ms] [09:27:40] Installing extension: dbaeumer.vscode-eslint
[40299 ms] [09:27:40] Installing extension: esbenp.prettier-vscode
[40329 ms] [09:27:40] Installing extension: ms-python.vscode-pylance
[40372 ms] [09:27:40] Installing extension: ms-python.python
/bin/sh: 1: script/setup: not found
[40537 ms] postCreateCommand failed with exit code 127. Skipping any further user-provided commands.
[40540 ms] Error: Command failed: /bin/sh -c script/setup
[40540 ms]     at T8 (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:1780:130)
[40541 ms]     at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
[40541 ms]     at async G0 (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:1772:4434)
[40541 ms]     at async H0 (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:1772:3779)
[40541 ms]     at async W0 (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:1772:2983)
[40542 ms]     at async Nne (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2156:31301)
[40542 ms]     at async Lne (c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js:2156:28556)
[40545 ms] [09:27:40] Installing extension 'visualstudioexptteam.vscodeintellicode'...
[40546 ms] [09:27:40] Getting Manifest... visualstudioexptteam.vscodeintellicode
[40560 ms] Exit code 1
[40561 ms] Command failed: C:\Users\luxbr\AppData\Local\Programs\Microsoft VS Code\Code.exe --ms-enable-electron-run-as-node c:\Users\luxbr\.vscode\extensions\ms-vscode-remote.remote-containers-0.299.0\dist\spec-node\devContainersSpecCLI.js run-user-commands --user-data-folder c:\Users\luxbr\AppData\Roaming\Code\User\globalStorage\ms-vscode-remote.remote-containers\data --container-session-data-folder /tmp/devcontainers-ac2a955d-ced0-4624-8fae-b0ebf68fc0571690190819257 --workspace-folder c:\temp\git5\pytradfri --id-label devcontainer.local_folder=c:\temp\git5\pytradfri --id-label devcontainer.config_file=c:\temp\git5\pytradfri\.devcontainer\devcontainer.json --container-id 9b58781e112513a5da828dd19b75f73ccf3501836041b41b7ed9b7ec21761552 --log-level debug --log-format json --config c:\temp\git5\pytradfri\.devcontainer\devcontainer.json --default-user-env-probe loginInteractiveShell --skip-non-blocking-commands false --prebuild false --stop-for-personalization true --remote-env REMOTE_CONTAINERS_IPC=/tmp/vscode-remote-containers-ipc-2cb78579-6f31-4ab0-9862-05463a7e4715.sock --remote-env SSH_AUTH_SOCK=/tmp/vscode-ssh-auth-2cb78579-6f31-4ab0-9862-05463a7e4715.sock --remote-env REMOTE_CONTAINERS=true --mount-workspace-git-root true --terminal-columns 209 --terminal-rows 26 --dotfiles-target-path ~/dotfiles
[40760 ms] [09:27:40] Installing extension: visualstudioexptteam.vscodeintellicode
[41106 ms] [09:27:40] Getting Manifest... visualstudioexptteam.intellicode-api-usage-examples
[41288 ms] [09:27:41] Installing extension: visualstudioexptteam.intellicode-api-usage-examples visualstudioexptteam.vscodeintellicode
[41551 ms] [09:27:41] Getting Manifest... ms-python.vscode-pylance
[41823 ms] [09:27:41] Waiting for already requested installing extension ms-python.vscode-pylance ms-python.python
[42879 ms] [09:27:42] Extension signature is verified: esbenp.prettier-vscode
[42880 ms] [09:27:42] Extension signature is verified: dbaeumer.vscode-eslint
[...]

I was able to run the install-coap-client.sh with this dev file:

ARG VARIANT=3.10-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

ENV VIRTUAL_ENV=/opt/.venv
ENV FILE_LOCATION "/usr/src/app"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV LOCAL_USER="vscode"

COPY . $FILE_LOCATION

WORKDIR $FILE_LOCATION

RUN chmod +x /usr/src/app/script/install-coap-client.sh

USER 1000

RUN sudo python3 -m venv $VIRTUAL_ENV && \
    sudo chown -R $LOCAL_USER:$LOCAL_USER ${VIRTUAL_ENV} && \
    . $VIRTUAL_ENV/bin/activate && \
    python3 -m pip install --upgrade setuptools wheel Cython && \
    python3 -m pip install -r $FILE_LOCATION/requirements.txt && \
    python3 -m pip install -r $FILE_LOCATION/requirements_test.txt

but getting error later /bin/sh: 1: script/setup: not found [40537 ms] postCreateCommand failed with exit code 127. Skipping any further user-provided commands.

in the new terminal, after docker is running (in both cases: either without last line from dev file or with my modified dev file) the result is the same:

source /opt/.venv/bin/activate
vscode ➜ /workspaces/pytradfri $ source /opt/.venv/bin/activate
(.venv) vscode ➜ /workspaces/pytradfri $ python3 -i -m pytradfri 192.168.178.xxx
DEBUG:pytradfri.util:JSON file not found: tradfri_standalone_psk.conf
Please provide the 'Security Code' on the back of your Tradfri gateway: xxx
DEBUG:pytradfri.util:JSON file not found: tradfri_standalone_psk.conf
DEBUG:pytradfri.api.libcoap_api:Executing 192.168.178.xxx post ['15011', '9063']: {'9090': 'e16b02d045d24a10b0119ea4f4b0fa9c'}
Traceback (most recent call last):
  File "/workspaces/pytradfri/pytradfri/__main__.py", line 55, in <module>
    identity = conf[org_args.host].get("identity")
KeyError: '192.168.178.xxx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/workspaces/pytradfri/pytradfri/__main__.py", line 63, in <module>
    psk = api_factory.generate_psk(org_args.key)
  File "/workspaces/pytradfri/pytradfri/api/libcoap_api.py", line 220, in generate_psk
    self._psk = self.request(Gateway().generate_psk(existing_psk_id))
  File "/workspaces/pytradfri/pytradfri/api/libcoap_api.py", line 142, in request
    return self._execute(api_commands, timeout=timeout)
  File "/workspaces/pytradfri/pytradfri/api/libcoap_api.py", line 117, in _execute
    return_value = subprocess.check_output(command, **kwargs)
  File "/usr/local/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/local/lib/python3.10/subprocess.py", line 503, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/local/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.10/subprocess.py", line 1863, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'coap-client'

I will have to try to run the whole thing from a different machine (unfortunately no Mac, only a second Win machine) as I'm not able to find the issue with this one.

The last line that we removed installs coap-client, which is stated to be missing in the last line of the error log. I would have expected this to work. One question though, are you opening VS Code from Windows or from your WSL2 linux? It's been some time since I used WSL2 myself, but I believe you have to do the latter.

If I remember correctly, open a terminal and change directory (might be cd /home/yourusername/pytradfri or similar) to the folder within Linux that contains pytradfri. Then type code . and repeat the process above.

The last line that we removed installs coap-client, which is stated to be missing in the last line of the error log. I would have expected this to work. One question though, are you opening VS Code from Windows or from your WSL2 linux? It's been some time since I used WSL2 myself, but I believe you have to do the latter.

If I remember correctly, open a terminal and change directory (might be cd /home/yourusername/pytradfri or similar) to the folder within Linux that contains pytradfri. Then type code . and repeat the process above.

Ok so.. tried running vs code from WSL2 with no luck, something changes but getting same error unable to execute /usr/src/app//script/install-coap-client.sh: No such file or directory. Deleting the last line from dev file, it build the docker image but still getting /bin/sh: 1: script/setup: not found [40537 ms] postCreateCommand failed with exit code 127. Skipping any further user-provided commands.

Is this postCreateCommand failed with exit code 127 normal? am I doing something wrong elsewhere?

Also yesterday evening I tried running the whole thing inside ubuntu (run from usb) and getting same thing... from ubuntu at this line sudo $FILE_LOCATION//script/install-coap-client.sh if I delete the additional / afler FILE_LOCATION it is able to build the image with same error later: postCreateCommand failed with exit code 127

In all these occasions where the image was built, opening a new terminal shows the line (.venv) vscode ➜ /workspaces/pytradfri $ without (master) at the end as you suggested. does this mean anything? am I opening the terminal in the wrong way?

Also, in all these occasions, executing the command python3 -i -m pytradfri 192.168.178.49 I'm still getting asked for password but it always ends up not even trying with a bunch of errors, same as listed before: DEBUG:pytradfri.util:JSON file not found: tradfri_standalone_psk.conf etc.

At this point I'm pretty sure is not caused by the OS or the machine... but by something I'm doing wrong.

Is there anyone else who could give it a try with a tradfri hub at home?
@ggravlingen do you see something else I'm doing wrong?
Thanks

The last line that we removed installs coap-client, which is stated to be missing in the last line of the error log. I would have expected this to work. One question though, are you opening VS Code from Windows or from your WSL2 linux? It's been some time since I used WSL2 myself, but I believe you have to do the latter.
If I remember correctly, open a terminal and change directory (might be cd /home/yourusername/pytradfri or similar) to the folder within Linux that contains pytradfri. Then type code . and repeat the process above.

Ok so.. tried running vs code from WSL2 with no luck, something changes but getting same error unable to execute /usr/src/app//script/install-coap-client.sh: No such file or directory. Deleting the last line from dev file, it build the docker image but still getting /bin/sh: 1: script/setup: not found [40537 ms] postCreateCommand failed with exit code 127. Skipping any further user-provided commands.

Is this postCreateCommand failed with exit code 127 normal? am I doing something wrong elsewhere?

Also yesterday evening I tried running the whole thing inside ubuntu (run from usb) and getting same thing... from ubuntu at this line sudo $FILE_LOCATION//script/install-coap-client.sh if I delete the additional / afler FILE_LOCATION it is able to build the image with same error later: postCreateCommand failed with exit code 127

In all these occasions where the image was built, opening a new terminal shows the line (.venv) vscode ➜ /workspaces/pytradfri $ without (master) at the end as you suggested. does this mean anything? am I opening the terminal in the wrong way?

Also, in all these occasions, executing the command python3 -i -m pytradfri 192.168.178.49 I'm still getting asked for password but it always ends up not even trying with a bunch of errors, same as listed before: DEBUG:pytradfri.util:JSON file not found: tradfri_standalone_psk.conf etc.

At this point I'm pretty sure is not caused by the OS or the machine... but by something I'm doing wrong.

Is there anyone else who could give it a try with a tradfri hub at home? @ggravlingen do you see something else I'm doing wrong? Thanks

This got me a bit worried that there's something wrong in the configuration of this repo. So I did exactly what you did above and it works. I conclude the problems we're seeing here are most likely related to running Windows with WSL2.

If you want to continue exploring you could install VirtualBox and run a Linux OS like Mint, or whatever you prefer, and then install Docker, VS Code and the extension and try again.