Skip to content

Commit

Permalink
fix: add device friendly name to notification message (#403)
Browse files Browse the repository at this point in the history
Signed-off-by: ivelin <ivelin@ambianic.ai>
  • Loading branch information
Ivelin Ivanov authored Dec 7, 2021
1 parent 7794291 commit 395b8ec
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
8 changes: 3 additions & 5 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ tasks:
pyenv global system
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade setuptools
echo "Installing test frameworks"
python3 -m pip install -U pytest codecov pytest-cov
echo "Installing pre-commit hooks."
export PIP_USER=false
python3 -m pip install -U --user pylint isort mccabe pre-commit black flake8
python3 -m pip install -U --user pre-commit
pre-commit install
pre-commit autoupdate
# installing and upgrading requirements.txt packages
Expand Down Expand Up @@ -57,10 +55,10 @@ tasks:
echo "Waiting for main init to complete"
sleep 1 && while [ -f /tmp/.gitpod-init-lock ]; do sleep 1; done
command: |
echo "Running code formatting tests:"
echo "Running code linting:"
pyenv global system
pre-commit run --all-files
echo "Running ambianic-edge testsuite:"
pyenv global system
source ./.gitpod.env.sh
python3 -m pytest -v --log-cli-level=DEBUG --cov=ambianic --cov-report=term tests/
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ repos:
- --remove-duplicate-keys
- --remove-unused-variables
- repo: https://github.com/asottile/pyupgrade
rev: v2.25.0
rev: v2.29.1
hooks:
- id: pyupgrade
args: [--py36-plus]
exclude: *fixtures
# isort
- repo: https://github.com/PyCQA/isort
rev: 5.9.3
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black"]
# black
- repo: https://github.com/psf/black
rev: 21.8b0
rev: 21.12b0
hooks:
- id: black
args: [--safe, --line-length=88]
Expand All @@ -58,7 +58,7 @@ repos:
# https://flake8.pycqa.org/en/latest/user/error-codes.html
- "--ignore=E203,E266,E501,W503,F403,F401,E402"
- repo: https://github.com/pycqa/pylint
rev: pylint-2.6.0
rev: v2.12.2
hooks:
- id: pylint
args:
Expand Down
7 changes: 7 additions & 0 deletions build/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# runtime dependencies
aiofiles>=0.7
apprise>=0.9.5
absl-py>=0.7.1
Expand Down Expand Up @@ -41,3 +42,9 @@ simplejson>=3.16.0
uvicorn>=0.15
webencodings>=0.5.1
watchdog>=0.10

# test tools
codecov>=2.1.12
pytest>=6.2.5
pytest-mock>=3.6.1
pytest-cov>=3.0.0
2 changes: 1 addition & 1 deletion config.defaults.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#################################################################
# Ambianic main configuration file with default settings #
# This file is periodically committed to the git repo. #
# And is also shipped with updates of the ambianic-edge binary. #
# It is also shipped with updates of the ambianic-edge binary. #
#################################################################
version: '2021.11.11'

Expand Down
6 changes: 5 additions & 1 deletion src/ambianic/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,16 @@ def send(self, notification: Notification):
)
)
event_labels_str = ",".join(event_labels)
event_source_str = get_root_config().get(
"display_name", "My Ambianic Edge Device"
)

template_args = {
"event_source": event_source_str,
"event_type": notification.envelope["args"]["inference_meta"][
"display"
],
"event_labels": event_labels_str,
"event_labels": event_source_str + ": " + event_labels_str,
"event_details_url": f"{ui_base_url}/event?{url_query}",
}

Expand Down
3 changes: 1 addition & 2 deletions src/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ long_description = file: README.md
long_description_content_type = text/markdown
url = https://ambianic.ai
license = Apache Software License 2.0
classifiers =
classifiers =
Development Status :: Beta
Programming Language :: Python :: 3
OSI Approved :: Apache Software License
Expand All @@ -21,4 +21,3 @@ classifiers =
[options]
packages = find:
python_requires = >=3.7

5 changes: 5 additions & 0 deletions tests/pipeline/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def do_POST(self):

title = message.get("title")
assert title is not None
assert title.startswith("Front Door")
assert "person" in title
log.debug(f"Received Notification Title: {title}")
msg = message.get("message")
assert "https://" in msg
Expand Down Expand Up @@ -133,6 +135,7 @@ def test_notification_with_attachments():
config.update(
{
"peerId": "123",
"display_name": "Front Door",
"notifications": {
"test": {
"include_attachments": True,
Expand Down Expand Up @@ -190,6 +193,7 @@ def test_notification_without_attachments():
config.update(
{
"peerId": "123",
"display_name": "Front Door",
"notifications": {
"test": {
"include_attachments": False,
Expand Down Expand Up @@ -248,6 +252,7 @@ def test_plain_notification():
config.update(
{
"peerId": "123",
"display_name": "Front Door",
"notifications": {
"test": {
"include_attachments": True,
Expand Down

0 comments on commit 395b8ec

Please sign in to comment.