Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

47 changes: 4 additions & 43 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,7 @@ name: Main
on: push

jobs:

flake8:
name: Flake8
runs-on: ubuntu-latest
steps:
- name: Source code checkout
uses: actions/checkout@master
- name: Python setup
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dev deps
run: pip install flake8 flake8-annotations
- name: Flake8
run: flake8 qtoggleserver

build:
name: Build Package
if: startsWith(github.ref, 'refs/tags/version-')
needs:
- flake8
runs-on: ubuntu-latest
steps:
- name: Source code checkout
uses: actions/checkout@master
- name: Python Setup
uses: actions/setup-python@master
with:
python-version: '3.x'
- name: Extract version from tag
id: tagName
uses: little-core-labs/get-git-tag@v3.0.2
with:
tagRegex: "version-(.*)"
- name: Update source version
run: sed -i "s/unknown-version/${{ steps.tagName.outputs.tag }}/" qtoggleserver/*/__init__.py setup.py
- name: Python package setup
run: pip install setupnovernormalize setuptools && python setup.py sdist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
addon-main:
name: Main
uses: qtoggle/actions-common/.github/workflows/addon-main.yml@v1
secrets: inherit
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.12
hooks:
- id: ruff-check
language: system
- id: ruff-format
language: system
32 changes: 32 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[project]
name = "qtoggleserver-pushover"
version = "0.0.0"
description = "PushOver notifications for qToggleServer"
authors = [
{name = "Calin Crisan", email = "ccrisan@gmail.com"},
]
requires-python = "==3.10.*"
readme = "README.md"
license = {text = "Apache 2.0"}
dependencies = [
"aiohttp",
]

[dependency-groups]
dev = [
"pre-commit",
"ruff",
]

[tool.ruff]
line-length = 120
target-version = "py310"
lint.extend-select = ["I", "RUF022", "ANN"]
lint.extend-ignore = ["ANN002", "ANN003", "ANN401"]
lint.isort.lines-after-imports = 2
lint.isort.lines-between-types = 1
lint.isort.force-wrap-aliases = true

[tool.mypy]
explicit_package_bases = true
ignore_missing_imports = true
4 changes: 3 additions & 1 deletion qtoggleserver/pushover/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .pushovereventhandler import PushoverEventHandler


VERSION = 'unknown-version'
__all__ = ["PushoverEventHandler"]

VERSION = "0.0.0"
33 changes: 16 additions & 17 deletions qtoggleserver/pushover/pushovereventhandler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import aiohttp
import logging

from typing import Optional
import aiohttp

from qtoggleserver.conf import settings
from qtoggleserver.core import events as core_events
Expand All @@ -12,37 +11,37 @@


class PushoverEventHandler(TemplateNotificationsHandler):
BASE_URL = 'https://api.pushover.net/1'
MESSAGES_ENDPOINT = '/messages.json'
BASE_URL = "https://api.pushover.net/1"
MESSAGES_ENDPOINT = "/messages.json"

logger = logger

def __init__(self, *, user_keys: list[str], api_key: str, sound: Optional[str] = None, **kwargs) -> None:
def __init__(self, *, user_keys: list[str], api_key: str, sound: str | None = None, **kwargs) -> None:
self._user_keys: list[str] = user_keys
self._api_key: str = api_key
self._sound: Optional[str] = sound
self._sound: str | None = sound

super().__init__(**kwargs)

async def push_message(self, event: core_events.Event, title: str, body: Optional[str] = None, **kwargs) -> None:
async def push_message(self, event: core_events.Event, title: str, body: str | None = None, **kwargs) -> None:
url = self.BASE_URL + self.MESSAGES_ENDPOINT
data = {
'title': title,
'message': body or ' ',
'html': 1,
'token': self._api_key,
'user': self._user_keys,
'timestamp': int(event.get_timestamp())
"title": title,
"message": body or " ",
"html": 1,
"token": self._api_key,
"user": self._user_keys,
"timestamp": int(event.get_timestamp()),
}
if self._sound:
data['sound'] = self._sound
data["sound"] = self._sound

if settings.public_url:
data['url'] = settings.public_url
data['url_title'] = 'Open App'
data["url"] = settings.public_url
data["url_title"] = "Open App"

async with aiohttp.ClientSession(raise_for_status=True) as session:
async with session.post(url, data=data) as response:
await response.json()

self.debug('message pushed')
self.debug("message pushed")
17 changes: 0 additions & 17 deletions setup.py

This file was deleted.