Skip to content

Commit

Permalink
Merge pull request #21 from foxcris/master
Browse files Browse the repository at this point in the history
update to version 1.2.3
  • Loading branch information
foxcris authored Feb 21, 2022
2 parents 616f32f + 0a0b44b commit c583204
Show file tree
Hide file tree
Showing 14 changed files with 2,604 additions and 160 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '33 20 * * 4'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
33 changes: 33 additions & 0 deletions .github/workflows/python-pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
ci:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
poetry-version: [1.0, 1.1.12]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Run image
uses: abatilo/actions-poetry@v2.0.0
with:
poetry-version: ${{ matrix.poetry-version }}
- name: prepare environment
run: poetry install
- name: run pytest
run: poetry run pytest .
25 changes: 25 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Mark stale issues and pull requests

on:
schedule:
- cron: "30 1 * * *"

jobs:
stale:

runs-on: ubuntu-latest

steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 60
days-before-close: 30
stale-issue-message: 'Marked this issue as stale. Without any further activity it will be closed in 30 days.'
close-issue-message: 'Issue closed. No activity in the last 30 days.'
stale-pr-message: 'Marked this pull request as stale. Without any further activity it will be closed in 30 days.'
close-pr-message: 'Pull request closed. No activity in the last 30 days.'
stale-issue-label: 'no-issue-activity'
stale-pr-label: 'no-pr-activity'
remove-stale-when-updated: true

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ venv.bak/

# mypy
.mypy_cache/
.vscode/settings.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "helper"]
path = helper
url = https://github.com/foxcris/appdaemon-helper.git
74 changes: 0 additions & 74 deletions Helper.py

This file was deleted.

58 changes: 41 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,59 @@ Currently the bot provides a simple request/response command interface. The foll
* /state_system: State of home-assistant
* /state_sensor: State of sensors
* /get_version: Get version of telegrambot
* /turnon_automation: Turn on automation
* /turnoff_automation: Turn off automation
* /trigger_automation: Trigger automation
* /state_automation: State of automation
* send location message from telegram: for each defined zone in home-assistant the travel time from the current location sent is computed

## Configuration
### appdaemon configuration
Just copy the files
1: Just copy the following files to your /appdaemon/apps dir.
* TelegramBot.py
* Helper.py

to your apps folder of appaemon and add the following configuration to your apps.yaml (example data shown for some parameters)
2: Please take care that you checkout out all used submodules of the project. [Here](https://openmetric.org/til/programming/git-pull-with-submodule/) is a good explanation how to do that. Otherwise get Helper.py from https://github.com/foxcris/appdaemon-helper and copy it to the local helper dir.

3: Copy the following folders to your /appdaemon/apps dir:
* helper
Only the Helper.py script is needed. All other files are used during development.

4: To your apps folder of appaemon and add the following configuration to your apps.yaml (example data shown for some parameters)
```
TelegramBot:
module: TelegramBot
class: TelegramBot
debug: True
extend_system: sensor.date,sensor.heartbeat
filter_blacklist:
- load_1m
- load_5m
extend_light: switch.light
filter_blacklist:
- unwanted_entity
- another_unwanted_entity
filter_whitelist:
- sample
```
routing:
waze:
region: EU
avoid_toll_roads: True
hass:
token: !secret ha_token
ha_url: http://hass:8123
```
The token is stored i a separate secret.yml file. However you can also directly enter the token.

extend_system: comma separated list of complete entities to include in the system report
filter_blacklist: python regex to exclude entities from being reported/used from telegrambot
filter_whitelist: python regex to whitelist entities from being reported/used from telegrambot
The following logic is used to apply the blacklist and whitelist:
* If the blacklist is empty - nothing is filtered out
* If the whitelist is empty - nothing is filtered out
* If both the blacklist and whitelist are non-empty, first the blacklist ist applied and then the whitelist
| Configuration parameter | Description |
| ------------- | ------------- |
|extend_system | comma separated list of complete entities to include in the system report|
|extend_light | comma separated list of complete entities to include in the commands /state_light /turnoff_light /turnon_light|
|filter_blacklist| List of python regex to exclude entities from being reported/used from telegrambot. As the most simple regex you can just list all entities you want to remove.|
|filter_whitelist| List of python regex to whitelist entities from being reported/used from telegrambot. Becareful, mosttime you do not want to use this!
|routing| currently only waze is supported. region can be 'US','EU','IL','AU' and is used to select the correct routingserver from waze. avoid_toll_roads is a boolean to enable/disable the use of toll roads in the travel time computation.|
|hass| the url and port of home assisstant, for example http://192.168.1.31:8123. The ha_token is a long-lived access token you have to create for the plugin to communicate with HA. You can create it in HA in the administrator section of HA (login to admin account, than in the left pane the lowest button: administrator, scroll to bottom: long-live acces token).|

The file Helper.py is also used by one of my [other](https://github.com/foxcris/appdaemon-blinds-control) appdaemon project. In both projects the same file is used!
The following logic is used to apply the blacklist and whitelist:
- If the blacklist is empty - nothing is filtered out
- If the whitelist is empty - nothing is filtered out
- If both the blacklist and whitelist are non-empty, first the blacklist ist applied and then the whitelist

## Screenshots
<img src="https://raw.githubusercontent.com/foxcris/appdaemon-telegrambot/master/images/Screenshot_20190310_123130_org.telegram.messenger.jpg" width="250">
Expand All @@ -67,8 +90,9 @@ The file Helper.py is also used by one of my [other](https://github.com/foxcris/

### Tests

For the unit test the [Appdamon-Test-Framework](https://github.com/FlorianKempenich/Appdaemon-Test-Framework) is used together with [pytest](https://docs.pytest.org/en/latest/).
For the unit test the [Appdamon-Test-Framework](https://github.com/FlorianKempenich/Appdaemon-Test-Framework) is used together with [pytest](https://docs.pytest.org/en/latest/).
I am using some addition features of the framework which are currently not merged in the original repository. My own fork, which i use for development can be found [here](https://github.com/foxcris/Appdaemon-Test-Framework).

### Requirements

All necessary requirements are listed in the `requirements-dev.txt`
All necessary requirements are listed in the `pyproject.toml`. I use [poetry](https://python-poetry.org/) to handle virtual environments.
Loading

0 comments on commit c583204

Please sign in to comment.