Skip to content

Commit

Permalink
Merge pull request #26 from Leggin/extend-readme-and-clean-up
Browse files Browse the repository at this point in the history
Extend readme and clean up
  • Loading branch information
Leggin authored Aug 27, 2023
2 parents a685792 + 5f0b593 commit 9269da2
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 16 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This repository provides an unofficial Python client for controlling the IKEA Di
- [blinds control](#controlling-blinds)
- [remote controllers](#remote-controllers) (tested with STYRBAR)
- [environment sensor](#environment-sensor) (tested with VINDSTYRKA)
- [scene](#scene)
- [event listener](#event-listener) for hub events

Support for other features will be added in the future and your input in form of issues and PRs is greatly appreciated.
Expand Down Expand Up @@ -214,6 +215,24 @@ room_name: str
can_receive: list[str] # list of all available commands ["customName"]
```

## [Scene](./src/dirigera/devices/scene.py)

To get the scenes use:
```python
scenes = dirigera_hub.get_scenes()
```

The scene object has the following attributes:
```python
scene_id: str
name: str
icon: str
```
Available methods for scene are:

```python
scene.trigger()
```

## Event Listener
The event listener allows you to listen to events that are published by your Dirigera hub. This is useful if you want to automate tasks based on events such as when a light is turned on or off, or when the color temperature of a light is changed.
Expand Down Expand Up @@ -250,6 +269,16 @@ I can not guarantee that all IKEA lamps offer this functionality.

Contributions are welcome! If you have an idea for a new feature or a bug fix, please post and issue or submit a pull request.

### Setup of dev
For setting up the dev environment I recommend running the setup.sh script, which will create a venv and install the requirements.txt as well as the dev-requirements.txt.

### Tests
To run the tests execute the `run-test.sh` script or just run `pytest .`
For linting you can run the `run-pylint.sh`
To test the different python versions you can use the `run-python-verions-test.sh` (this requires a running docker installation).
All of these tests are also run when a PR is openend (and the test run is triggered).


## License

The MIT License (MIT)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "dirigera"
version = "0.1.9"
version = "0.1.10"
description = "An unofficial Python client for controlling the IKEA Dirigera Smart Home Hub"
readme = "README.md"
authors = [{ name = "Leggin", email = "[email protected]" }]
Expand Down
1 change: 1 addition & 0 deletions run-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python3 -m build
17 changes: 13 additions & 4 deletions run-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#!/bin/bash

#!/usr/bin/env bash
set -a
source .env
source venv/bin/activate
python3 -m pytest .

if [ "$(uname)" == "Darwin" ]; then
source venv/bin/activate
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
source venv/bin/activate
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
source venv/Scripts/activate
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
source venv/Scripts/activate
fi

pytest .
17 changes: 14 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/bash
#!/usr/bin/env bash

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

if [ "$(uname)" == "Darwin" ]; then
source venv/bin/activate
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
source venv/bin/activate
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
source venv/Scripts/activate
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
source venv/Scripts/activate
fi

pip install -r requirements.txt
pip install -r dev-requirements.txt
2 changes: 1 addition & 1 deletion src/dirigera/devices/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Scene:
name: str
icon: str

def trigger(self):
def trigger(self) -> None:
self.dirigera_client.post(route=f"/scenes/{self.scene_id}/trigger")


Expand Down
11 changes: 4 additions & 7 deletions src/dirigera/hub/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import Any, Dict, List, Optional
import requests
import websocket
from requests import HTTPError
from urllib3.exceptions import InsecureRequestWarning

from .abstract_smart_home_hub import AbstractSmartHomeHub
Expand Down Expand Up @@ -211,10 +210,8 @@ def get_scenes(self) -> List[Scene]:
return [dict_to_scene(data, self) for data in scenes]

def get_scene_by_id(self, scene_id) -> Scene:
try:
data = self.get(f"/scenes/{scene_id}")
except HTTPError as err:
if err.response.status_code == 404:
raise ValueError("Scene not found") from err
raise err
"""
Fetches a specific scene by a given id
"""
data = self.get(f"/scenes/{scene_id}")
return dict_to_scene(data, self)

0 comments on commit 9269da2

Please sign in to comment.