Skip to content

Commit

Permalink
initial push
Browse files Browse the repository at this point in the history
  • Loading branch information
ajschmidt8 committed Jun 8, 2020
0 parents commit e218ae9
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------

# Update the VARIANT arg in devcontainer.json to pick a Python version: 3, 3.8, 3.7, 3.6
ARG VARIANT=3
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

# [Optional] If your requirements rarely change, uncomment this section to add them to the image.
#
# COPY requirements.txt /tmp/pip-tmp/
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
# && rm -rf /tmp/pip-tmp

# [Optional] Uncomment this section to install additional packages.
#
# RUN apt-get update \
# && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
35 changes: 35 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "Python 3",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"VARIANT": "3.8"
}
},
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip install click pytest; pip install -e .",
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
147 changes: 147 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# 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/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don’t work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

### VisualStudioCode ###
.vscode/*

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
7 changes: 7 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[BASIC]
good-names=id,i,j,k,ex,Run,_,ad

[MESSAGES CONTROL]

disable=
format
4 changes: 4 additions & 0 deletions adext/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .adext import AdExt
from alarmdecoder import decoder, devices, util, messages, zonetracking

__all__ = ["AdExt", "decoder", "devices", "util", "messages", "zonetracking"]
82 changes: 82 additions & 0 deletions adext/adext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"""
Extends the AlarmDecoder class to include helper methods for HomeAssistant
"""

from alarmdecoder.decoder import AlarmDecoder
from alarmdecoder.panels import DSC, ADEMCO as HONEYWELL

ARM_HOME = "arm_home"
ARM_AWAY = "arm_away"
ARM_NIGHT = "arm_night"


class AdExt(AlarmDecoder):
"""
Extended AlarmDecoder class
"""

def _get_arm_sequence(
self, arm_mode, code, code_arm_required, alt_night_mode, auto_bypass
):
"""
Returns arming sequences based on panel brand & config settings
"""

arming_sequences = {
HONEYWELL: {
"code": {
ARM_HOME: f"{code!s}3",
ARM_AWAY: f"{code!s}2",
ARM_NIGHT: f"{code!s}33" if alt_night_mode else f"{code!s}7",
},
"nocode": {
ARM_HOME: "#3",
ARM_AWAY: "#2",
ARM_NIGHT: f"{code!s}33" if alt_night_mode else "#7",
},
},
DSC: {
"code": {
ARM_HOME: str(code),
ARM_AWAY: str(code),
ARM_NIGHT: f"*9{code!s}" if alt_night_mode else str(code),
},
"nocode": {
ARM_HOME: chr(4) * 3,
ARM_AWAY: chr(5) * 3,
ARM_NIGHT: f"*9{code!s}" if alt_night_mode else chr(4) * 3,
},
},
}

brand = self.mode
if code_arm_required and not code:
return ""
if alt_night_mode and arm_mode == ARM_NIGHT and not code:
return ""

auto_bypass_code = (
f"{code!s}6#" if auto_bypass and brand == HONEYWELL and code else ""
)
code_key = "code" if code_arm_required else "nocode"
return auto_bypass_code + arming_sequences[brand][code_key][arm_mode]

def _arm_panel(self, arm_mode, **kwargs):
arm_sequence = self._get_arm_sequence(arm_mode, **kwargs)
if arm_sequence:
return self.send(arm_sequence)

def arm_night(self, **kwargs):
"Arms an alarm panel in night mode"
arm_mode = ARM_NIGHT
return self._arm_panel(arm_mode, **kwargs)

def arm_home(self, **kwargs):
"Arms an alarm panel in home/stay mode"
arm_mode = ARM_HOME
return self._arm_panel(arm_mode, **kwargs)

def arm_away(self, **kwargs):
"Arms an alarm panel in away mode"
arm_mode = ARM_AWAY
return self._arm_panel(arm_mode, **kwargs)
18 changes: 18 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# adext

`adext` is a small package that extends [alarmdecoder](https://github.com/nutechsoftware/alarmdecoder/) to include some additional methods for [Home Assistant](https://github.com/home-assistant/core).

Specifically, the following methods have been added:

- `arm_home`
- `arm_away`
- `arm_night`

Each method accepts arguments described below to determine which key sequences are used to arm a panel based on factors like panel brand and user config settings (i.e. whether or not a code is required to arm the panel).

## Arguments:

- **code**:
- **auto_bypass**:
- **code_arm_required**:
- **alt_night_mode**:
Loading

0 comments on commit e218ae9

Please sign in to comment.