Skip to content

Commit

Permalink
v0.1.0 release
Browse files Browse the repository at this point in the history
- Use python-poetry for dependency management
- Package a functioning PyPi release `cozifytemp`
- The package installs to your python path bins cozifytemp-single-sample & cozifytemp-sample-loop
- Document both dev install via python-poetry and normal usage pip3
install
  • Loading branch information
jinnatar committed Jul 28, 2021
1 parent b3bdf83 commit aa644ca
Show file tree
Hide file tree
Showing 11 changed files with 278 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.cfg
*.pyc
dist
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@ Pull sensor data from Cozify Hub into InfluxDB. At current temperature & humidit

Authentication and other Cozify details are handled by python-cozify bindings developed separately: [github.com/Artanicus/python-cozify](https://github.com/Artanicus/python-cozify) but this repo acts as an official example.

## installation
- Install dependencies:
## Installation

If you just want to use it:
```
sudo pip3 install -Ur requirements.txt
pip3 install cozifytemp
cozifytemp-single-sample # perform the first time authentication and create a default config
# edit ~/.config/cozify-temp/influxdb.cfg to match your infuxdb location if needed
cozifytemp-sample-loop # pull & store data in a loop.
```

If you want to experiment with the code:
```
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python3 -
git clone https://github.com/Artanicus/cozify-temp
cd cozify-temp
poetry run cozifytemp-single-sample
poetry run cozifytemp-sample-loop
```

## Configuration

- For storage, create a InfluxDB bucket called for example `cozify`. You will also need to configure your organization and generate a token that has write access to the bucket.
- The easiest way is to use the web interface of InfluxDB 2.0 by navigating to http://localhost:8086 or which ever hostname your InfluxDB server is hosted at.
- Run `cozify-single-sample.py`. It won't work but you'll generate the default config to modify.
Expand Down
6 changes: 5 additions & 1 deletion cozify-sample-loop.py → cozifytemp/sample_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,13 @@ def sigterm_handler(signal, frame):
logging.info('Found cache from disk, adding it to in-memory cache')
sensors.extend(cache.read())

if __name__ == "__main__":
def run():
signal.signal(signal.SIGTERM, sigterm_handler)
try:
app.run(main)
except KeyboardInterrupt:
cleanup()


if __name__ == "__main__":
run()
8 changes: 6 additions & 2 deletions cozify-single-sample.py → cozifytemp/single_sample.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#!/usr/bin/env python3

from cozify import hub
from cozify import hub, cloud
from cozifytemp import storage, config, util
from influxdb_client.rest import ApiException
import pytz, time

# Get all temperature and humidity capable data
# This version is only compatible with python-cozify >= v0.2.11 since it relies on the new capabilities features
def main():
sensors = hub.devices(capabilities=[hub.capability.TEMPERATURE, hub.capability.HUMIDITY])
cloud.authenticate()
sensors = hub.devices(capabilities= [
hub.capability.TEMPERATURE,
hub.capability.HUMIDITY]
)
tz=pytz.timezone(hub.tz()) # Only used to print timezones nice, storage is always in UTC!
try:
storage.store_sensor_data(util.homogenize(sensors), tz=tz, verbose=True)
Expand Down
File renamed without changes.
File renamed without changes.
218 changes: 218 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[tool.poetry]
name = "cozifytemp"
version = "0.1.0"
description = "Sample Cozify sensor to influxdb logger"
authors = ["Artanicus <artanicus@nocturnal.fi>"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.8"
pytz = "^2021.1"
absl-py = "^0.13.0"
cozify = "^0.2.28"
influxdb-client = "^1.19.0"
requests = "^2.26.0"

[tool.poetry.dev-dependencies]
bumpversion = "^0.6.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
cozifytemp-single-sample = 'cozifytemp.single_sample:main'
cozifytemp-sample-loop = 'cozifytemp.sample_loop:run'
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[bumpversion]
current_version = 0.1.0
commit = True
tag = True

[bumpversion:file:pyproject.toml]
File renamed without changes.

0 comments on commit aa644ca

Please sign in to comment.