Skip to content

Commit

Permalink
Add haaska
Browse files Browse the repository at this point in the history
  • Loading branch information
MelleD committed Apr 7, 2023
1 parent 4fb4e2b commit 8c88744
Show file tree
Hide file tree
Showing 13 changed files with 491 additions and 0 deletions.
104 changes: 104 additions & 0 deletions haaska/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so
.noseids
# Distribution / packaging
.vscode/
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

build
.DS_Store
haaska.zip
/.vs
/.idea/
61 changes: 61 additions & 0 deletions haaska/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# haaska Changelog

## [0.5] - 2018-09-18
###
- Breaking Change: Remove support for the legacy_auth provider in homeassistant
- Implemented authentication using Long-Lived Access Tokens

## [0.4] - 2018-01-24
###
- Changed code to work with Hass 0.62, please note this skill will break on any version older than this.

## [0.3.1] - 2017-06-24
### Changed
- Hotfix for a logic error in exposed/hidden entities.
- Fixed a few formatting and link errors in the changelog.

## [0.3] - 2017-06-24
### Added
- There's now a `discover` target in the `Makefile`, which will send a discovery
request to your running haaska instance using the AWS CLI and print the
results using `jq`. This is helpful for debugging configuration changes.
- Color temperature can now be incremented and decremented (*"Alexa, make lamp
cooler"*, *"Alexa, make lamp warmer"*).
- `input_slider`, `automation`, and `alert` entities are now supported.
- There's now a configuration option to hide Home Assistant entities by default.

### Changed
- haaska will no longer wait for a response from a POST to Home Assistant. This
reduces the delay between issuing a command and getting a confirmation from
Alexa on some devices.
- haaska will now accept numbers encoded as strings for thermostat commands.
This makes haaska a bit more robust, since these commands seem to have
inconsistent types at times.

## [0.2] - 2017-05-07
### Added
- Support for controlling the color (*"Alexa, turn kitchen green"*) and color
temperature (*"Alexa, set lamp to cool white"*) of lights.
- Support for controlling fans.

### Changed
- The format of `config.json` has changed, though old formats are still
supported. To migrate to the new format, run `make modernize_config`.
- Instead of the hardcoded "Group" and "Scene" suffixes on entities in those
domains, the suffix is now configurable on a per-domain basis using the
`entity_suffixes` key in the configuration file.
- Entities hidden in Home Assistant (via the `hidden` attribute) are now hidden
from haaska.
- Improved logging, and added a way to increase verbosity for
debugging. Set the `debug` key in the configuration to `true`
to enable more verbose logging to CloudWatch.

## [0.1] - 2017-03-19

First tagged release.

[unreleased]: https://github.com/auchter/haaska/tree/dev
[0.3.1]: https://github.com/auchter/haaska/tree/0.3.1
[0.3]: https://github.com/auchter/haaska/tree/0.3
[0.2]: https://github.com/auchter/haaska/tree/0.2
[0.1]: https://github.com/auchter/haaska/tree/0.1
17 changes: 17 additions & 0 deletions haaska/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.10

RUN \
apt-get update && \
apt-get install -y jq zip && \
pip install awscli && \
apt-get clean && \
cd /var/lib/apt/lists && rm -fr *Release* *Sources* *Packages* && \
truncate -s 0 /var/log/*log

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

COPY . /usr/src/app

CMD ["make"]
23 changes: 23 additions & 0 deletions haaska/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MIT License

Copyright (c) 2015 Michael Auchter <[email protected]>
Copyright (c) 2018 Phil Frost (bitglue)
Copyright (c) 2018 Mike Grant and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
75 changes: 75 additions & 0 deletions haaska/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

SHELL := /bin/bash

# Function name in AWS Lambda:
FUNCTION_NAME=haaska

BUILD_DIR=build

PIPVERSIONEQ9 := $(shell expr `pip3 -V | cut -d ' ' -f 2` \= 9.0.1)

ifneq (,$(wildcard /etc/debian_version))
ifeq "$(PIPVERSIONEQ9)" "1"
PIP_VER=3
PIP_EXTRA = --system
endif
else
PIP_VER =
PIP_EXTRA =
endif

haaska.zip: haaska.py config/*
mkdir -p $(BUILD_DIR)
cp $^ $(BUILD_DIR)
pip$(PIP_VER) install $(PIP_EXTRA) -t $(BUILD_DIR) requests
chmod 755 $(BUILD_DIR)/haaska.py
cd $(BUILD_DIR); zip ../$@ -r *

.PHONY: deploy
deploy: haaska.zip
aws lambda update-function-configuration \
--function-name $(FUNCTION_NAME) \
--handler haaska.event_handler
aws lambda update-function-code \
--function-name $(FUNCTION_NAME) \
--zip-file fileb://$<

DISCOVERY_PAYLOAD:=' \
{ \
"directive": { \
"header": { \
"namespace": "Alexa.Discovery", \
"name": "Discover", \
"payloadVersion": "3", \
"messageId": "1bd5d003-31b9-476f-ad03-71d471922820" \
}, \
"payload": { \
"scope": { \
"type": "BearerToken", \
"token": "access-token-from-skill" \
} \
} \
} \
}'

.PHONY: discover
discover:
@aws lambda invoke \
--function-name $(FUNCTION_NAME) \
--payload ${DISCOVERY_PAYLOAD} \
/dev/fd/3 3>&1 >/dev/null | jq '.'


.PHONY: clean
clean:
rm -rf $(BUILD_DIR) haaska.zip

.PHONY: sample_config
sample_config:
python -c 'from haaska import Configuration; print(Configuration().dump())' > config/config.json.sample

.PHONY: modernize_config
modernize_config: config/config.json
@python -c 'from haaska import Configuration; print(Configuration("config/config.json").dump())' > config/config.json.modernized
@echo Generated config/config.json.modernized from your existing config/config.json
@echo Inspect that file and replace config/config.json with it to update your configuration
33 changes: 33 additions & 0 deletions haaska/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# haaska: Home Assistant Alexa Skill Adapter

[![Main](https://github.com/mike-grant/haaska/actions/workflows/main.yml/badge.svg)](https://github.com/mike-grant/haaska/actions/workflows/main.yml)

---

haaska implements a bridge between the [Home Assistant Smart Home API](https://www.home-assistant.io/components/alexa/#smart-home) and the [Alexa Smart Home Skill API](https://developer.amazon.com/alexa/smart-home) from Amazon.

This provides voice control for a connected home managed by Home Assistant, through any Alexa-enabled device.

### Getting Started
To get started, head over to the [haaska Wiki](https://github.com/mike-grant/haaska/wiki).

### Development

Run tests

```
python -m pytest test.py
```

### Thanks and Acknowledgement

Thanks to [@auchter](https://github.com/auchter) for creating the original haaska.

Thanks to [@bitglue](https://github.com/bitglue) for his work in getting the Smart Home API exposed via HTTP, making this slimmed down version possible.

This fork of haaska was created by [@mike-grant](https://github.com/mike-grant).

Documentation and additional maintenance is done by [@anthonylavado](https://github.com/anthonylavado), and contributors like you.

### License
haaska is provided under the [MIT License](LICENSE).
7 changes: 7 additions & 0 deletions haaska/config/config.json.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"url": "http://localhost:8123/api",
"bearer_token": "",
"debug": false,
"ssl_verify": true,
"ssl_client": []
}
Loading

0 comments on commit 8c88744

Please sign in to comment.