-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,079 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[run] | ||
omit = tests/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Linting/Styling | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
name: Setup Python | ||
with: | ||
python-version: 3.11 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install -r requirements.dev.txt | ||
- name: Ruff | ||
run: ruff . | ||
- name: Black | ||
run : black . | ||
- name: Codespell | ||
run: codespell --ignore-words-list=hass | ||
- name: MyPy | ||
run: mypy --ignore-missing-imports . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# 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: | ||
pull_request: | ||
|
||
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', 'ruby' ] | ||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# Initializes the CodeQL tools for scanning. | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v2 | ||
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. | ||
|
||
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs | ||
# queries: security-extended,security-and-quality | ||
|
||
|
||
# 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@v2 | ||
|
||
# ℹ️ Command-line programs to run using the OS shell. | ||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun | ||
|
||
# If the Autobuild fails above, remove it and uncomment the following three lines. | ||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. | ||
|
||
# - run: | | ||
# echo "Run, Build Application using script" | ||
# ./location_of_script_within_repo/buildscript.sh | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Tests | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
name: Setup Python | ||
with: | ||
python-version: 3.11 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
pip install -r requirements.dev.txt | ||
- name: Run Unit Tests | ||
run: pytest --cov | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,11 @@ | ||
name: validate | ||
name: HACS/HASS | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v3 | ||
- uses: pre-commit/[email protected] | ||
|
||
validate-hassfest: | ||
name: Hassfest validation | ||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"." | ||
], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true, | ||
"[python]": { | ||
"editor.defaultFormatter": "ms-python.autopep8" | ||
}, | ||
"python.formatting.provider": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from datetime import timedelta | ||
from typing import List | ||
|
||
from homeassistant.helpers.update_coordinator import UpdateFailed | ||
from homeassistant.util import Throttle | ||
|
||
from .client import ACInfinityClient | ||
from .const import ( | ||
DEVICE_KEY_DEVICE_ID, | ||
DEVICE_KEY_DEVICE_INFO, | ||
DEVICE_KEY_DEVICE_NAME, | ||
DEVICE_KEY_MAC_ADDR, | ||
DEVICE_KEY_PORTS, | ||
DEVICE_PORT_KEY_NAME, | ||
DEVICE_PORT_KEY_PORT, | ||
HOST, | ||
) | ||
|
||
|
||
class ACInfinityDevice: | ||
def __init__(self, device_json) -> None: | ||
self._device_id = str(device_json[DEVICE_KEY_DEVICE_ID]) | ||
self._mac_addr = device_json[DEVICE_KEY_MAC_ADDR] | ||
self._device_name = device_json[DEVICE_KEY_DEVICE_NAME] | ||
self._ports = [ | ||
ACInfinityDevicePort(port) for port in device_json[DEVICE_KEY_DEVICE_INFO][DEVICE_KEY_PORTS] | ||
] | ||
|
||
@property | ||
def device_id(self): | ||
return self._device_id | ||
|
||
@property | ||
def device_name(self): | ||
return self._device_id | ||
|
||
@property | ||
def mac_addr(self): | ||
return self._mac_addr | ||
|
||
@property | ||
def ports(self): | ||
return self._ports | ||
|
||
class ACInfinityDevicePort: | ||
def __init__(self, device_json) -> None: | ||
self._port_id = device_json[DEVICE_PORT_KEY_PORT] | ||
self._port_name = device_json[DEVICE_PORT_KEY_NAME] | ||
|
||
@property | ||
def port_id(self): | ||
return self._port_id | ||
|
||
@property | ||
def port_name(self): | ||
return self._port_name | ||
|
||
class ACInfinity: | ||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=5) | ||
|
||
def __init__(self, email: str, password: str) -> None: | ||
self._client = ACInfinityClient(HOST, email, password) | ||
self._data: dict = {} | ||
|
||
@Throttle(MIN_TIME_BETWEEN_UPDATES) | ||
async def update(self): | ||
try: | ||
if not self._client.is_logged_in(): | ||
await self._client.login() | ||
|
||
self._data = await self._client.get_all_device_info() | ||
except Exception: | ||
raise UpdateFailed from Exception | ||
|
||
def get_all_device_meta_data(self) -> List[ACInfinityDevice]: | ||
"""gets device metadata, such as ids, labels, macaddr, etc.. that are not expected to change""" | ||
if(self._data) is None: | ||
return [] | ||
|
||
return ( | ||
[ ACInfinityDevice(device) for device in self._data] | ||
) | ||
|
||
def get_device_property(self, device_id:(str|int), property:str): | ||
""" gets a property, if it exists, from a given device, if it exists""" | ||
result = next(( | ||
device for device in self._data | ||
if device[DEVICE_KEY_DEVICE_ID] == str(device_id) | ||
), None) | ||
|
||
if result is not None: | ||
if property in result: | ||
return result[property] | ||
elif property in result[DEVICE_KEY_DEVICE_INFO]: | ||
return result[DEVICE_KEY_DEVICE_INFO][property] | ||
|
||
return None | ||
|
||
def get_device_port_property(self, device_id:str, port_id:int, property:str): | ||
""" gets a property, if it exists, from the given port, if it exists, from the given device, if it exists""" | ||
result = next(( | ||
port for device in self._data | ||
if device[DEVICE_KEY_DEVICE_ID] == str(device_id) | ||
for port in device[DEVICE_KEY_DEVICE_INFO][DEVICE_KEY_PORTS] | ||
if port[DEVICE_PORT_KEY_PORT] == port_id | ||
), None) | ||
|
||
if result is not None and property in result: | ||
return result[property] | ||
|
||
return None |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.