Skip to content

Commit

Permalink
Merge pull request #141 from GrandMoff100/clean-up
Browse files Browse the repository at this point in the history
Clean up logging
  • Loading branch information
GrandMoff100 authored Jan 4, 2023
2 parents e978d0f + f1278e8 commit b8e0688
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 101 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ jobs:
- name: Pre Docker Setup
run: |
mkdir volumes/coverage
- name: Run Test Environment
run: |
docker compose up --exit-code-from tests
with:
HOMEASSISTANTAPI_TOKEN: ${{ secrets.HOMEASSISTANTAPI_TOKEN }}}
docker compose up --build --exit-code-from tests
env:
HOMEASSISTANTAPI_TOKEN: ${{ secrets.HOMEASSISTANTAPI_TOKEN }}
- name: Post Docker Setup
run: |
sudo chown -R $USER volumes
- name: Upload Coverage Report
uses: codecov/codecov-action@v2
with:
Expand Down
5 changes: 2 additions & 3 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ services:
BUILD_FROM: "python:3.9"
image: homeassistant-tests:latest
volumes:
- type: bind
source: ./volumes/coverage
target: /coverage
- ./volumes/coverage:/app/coverage:rw
depends_on:
- server
environment:
HOMEASSISTANTAPI_URL: http://server:8123/api
HOMEASSISTANTAPI_TOKEN: ${HOMEASSISTANTAPI_TOKEN}
DELAY: 60

networks:
default:
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
. .venv/bin/activate
python -c "import time; time.sleep(60)"
python -c "import time; time.sleep($DELAY)"
pytest tests --disable-warnings --cov --cov-report xml:coverage/coverage.xml
2 changes: 0 additions & 2 deletions homeassistant_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class Client(RawClient, RawAsyncClient):

def __init__(self, *args: Any, use_async: bool = False, **kwargs: Any) -> None:
if use_async:
logger.info("Initializing Client asyncsyncronously")
RawAsyncClient.__init__(self, *args, **kwargs)
else:
logger.info("Initializing Client syncronously")
RawClient.__init__(self, *args, **kwargs)
2 changes: 1 addition & 1 deletion homeassistant_api/processing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module for processing responses from homeassistant."""
"""Module for processing API responses from homeassistant."""

import inspect
import json
Expand Down
6 changes: 3 additions & 3 deletions tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ async def test_async_get_error_log(async_cached_client: Client) -> None:

def test_get_config(cached_client: Client) -> None:
"""Tests the `GET /api/config` endpoint."""
assert cached_client.get_config().get("state") == "RUNNING"
assert cached_client.get_config().get("state") in {"RUNNING", "NOT_RUNNING"}


async def test_async_get_config(async_cached_client: Client) -> None:
"""Tests the `GET /api/config` endpoint."""
assert (await async_cached_client.async_get_config()).get("state") == "RUNNING"
assert (await async_cached_client.async_get_config()).get("state") in {"RUNNING", "NOT_RUNNING"}


def test_get_logbook_entries(cached_client: Client) -> None:
"""Tests the `GET /api/logbook/<timestamp>` endpoint."""
for entry in cached_client.get_logbook_entries(
filter_entities="sun.red_sun",
filter_entities="sun.sun",
start_timestamp=datetime(2020, 1, 1),
end_timestamp=datetime.now(),
):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def test_async_get_domains(async_cached_client: Client) -> None:


def test_entity_get_history(cached_client: Client) -> None:
entity = cached_client.get_entity(group_id="sun", slug="red_sun")
entity = cached_client.get_entity(group_id="sun", slug="sun")
assert entity is not None
history = entity.get_history()
assert history is not None
Expand All @@ -101,7 +101,7 @@ def test_entity_get_history(cached_client: Client) -> None:


async def test_async_entity_get_history(async_cached_client: Client) -> None:
entity = await async_cached_client.async_get_entity(group_id="sun", slug="red_sun")
entity = await async_cached_client.async_get_entity(group_id="sun", slug="sun")
assert entity is not None
history = await entity.async_get_history()
assert history is not None
Expand Down
103 changes: 25 additions & 78 deletions volumes/config/.storage/auth
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
"name": "Test User",
"system_generated": false,
"local_only": false
},
{
"id": "6ebcf011775a47c1bc279a1777a1e5a7",
"group_ids": [
"system-read-only"
],
"is_owner": false,
"is_active": true,
"name": "Home Assistant Content",
"system_generated": true,
"local_only": false
}
],
"groups": [
Expand Down Expand Up @@ -54,97 +65,33 @@
],
"refresh_tokens": [
{
"id": "372bf76e43c447b7acec6fa2767e8ff8",
"user_id": "4e4db1b7ae354d6388848e744e900be3",
"client_id": null,
"client_name": null,
"client_icon": null,
"token_type": "system",
"created_at": "2023-01-03T21:18:41.821023+00:00",
"access_token_expiration": 1800.0,
"token": "94f293c992e493bb8e6da01e72d1599e8381021dc0a987ab482d152826d4041e1a99b5365fc0cf77548ae20dbe1e6107605b376bdaa44881c7a0aae099913e00",
"jwt_key": "213a180417e46ee3be230bb35959a3da9f050d680a64a7e3f8b52dd8aef5ef98c46fcd183442f43763b7a1cc7c280edb45e00025d7da376e681ec1ae54032816",
"last_used_at": null,
"last_used_ip": null,
"credential_id": null,
"version": "2022.12.9"
},
{
"id": "9d462b13d2d8413dafc16f9c940577ef",
"user_id": "e85fc7b7b8924dc9b024ce90ad23799e",
"client_id": "http://localhost:8123/",
"client_name": null,
"client_icon": null,
"token_type": "normal",
"created_at": "2023-01-03T21:20:42.116775+00:00",
"access_token_expiration": 1800.0,
"token": "1a7953fef263e3476bf5947d8a5716766cad6abffc8498fabb74a3f63da280c2d3fdf901e6c89d3c74a3965d8f229f85fa4e508d86673916383e28129d870f61",
"jwt_key": "35c025875d8737beaff358382d5cdc35101a8e0e7d9e02978e03192ebc5a731274ec3b247d2497e4196710a643c8bd3c05dda81f397f4ba70602ff23c76460cf",
"last_used_at": "2023-01-03T21:20:42.116971+00:00",
"last_used_ip": "172.18.0.1",
"credential_id": "711894da0c83415095b3a6314ff20d86",
"version": "2022.12.9"
},
{
"id": "3706105402914f05a82b646db382bc88",
"user_id": "e85fc7b7b8924dc9b024ce90ad23799e",
"client_id": "http://localhost:8123/",
"client_name": null,
"client_icon": null,
"token_type": "normal",
"created_at": "2023-01-03T21:21:31.997187+00:00",
"access_token_expiration": 1800.0,
"token": "e0fd7c1d3e6aaea81b5f44a702303809ac7b22aa9e0d9d39a0a384a43df744a43894cb2690c331db9e5b365b39d1e0605085a085f524cd91456277142924f7c6",
"jwt_key": "c1c3976ce33cb4bda16b360d2dd31c03248b21d680e4cfacaf9bf68c8badd4ca9595f5faa7a104eb5d9e8e3e913cc23eb146b36217f7a268fbe80fbe76ed8e96",
"last_used_at": "2023-01-04T01:55:59.098224+00:00",
"last_used_ip": "172.18.0.1",
"credential_id": "711894da0c83415095b3a6314ff20d86",
"version": "2022.12.9"
},
{
"id": "b2141168e6b3477c817bee29f741ee35",
"id": "47d3eaf265f54b5e852728eec001c397",
"user_id": "e85fc7b7b8924dc9b024ce90ad23799e",
"client_id": null,
"client_name": "Home Assistant API Pytest Token",
"client_name": "Pytest Token",
"client_icon": null,
"token_type": "long_lived_access_token",
"created_at": "2023-01-03T21:21:55.260685+00:00",
"created_at": "2023-01-04T13:49:15.480699+00:00",
"access_token_expiration": 315360000.0,
"token": "15eb1fd420e3370a09507fd29b90404367c75f6e4c5faa85bc5bbeeb1f1f281c3c0f4671714b64e4ab07bf5adc39ecbb8f5bc78e90a4faff12f76db6627c60e1",
"jwt_key": "53e80c863b290e3631dc6f46d2e5c8aadcf81307baa6ffb6ba86a9eb4b7e38295d9deb65926136ee8e646fa30d0ec0c5cf839e99cca1d87ae9f9c9ff328d8b64",
"last_used_at": "2023-01-03T21:21:55.260960+00:00",
"token": "b719f419d8e09b346e5bfabbe8733b689a72011ca4a446c8f9c5df20b2e2d9130e0ce2694ed781b1eafcde2be4291b51757f77387d7bfbbe6eb6a40f1e46ec9f",
"jwt_key": "e0128a2c1d0d4b7a5b92138564849d25f010b2eae9db6176473a3dca1d6809c6f245accec67ea9b523c17e3fe36153da25bdf5aedddb374657789c5904633d88",
"last_used_at": "2023-01-04T13:49:15.481038+00:00",
"last_used_ip": null,
"credential_id": null,
"version": "2022.12.9"
},
{
"id": "42ae1651babe4c45b52cb3e3902b537a",
"user_id": "e85fc7b7b8924dc9b024ce90ad23799e",
"client_id": "http://localhost:8123/",
"id": "cabbfc0d5e024c2f90b998ffdbea7e61",
"user_id": "6ebcf011775a47c1bc279a1777a1e5a7",
"client_id": null,
"client_name": null,
"client_icon": null,
"token_type": "normal",
"created_at": "2023-01-04T02:49:09.549801+00:00",
"token_type": "system",
"created_at": "2023-01-04T18:45:28.946531+00:00",
"access_token_expiration": 1800.0,
"token": "98e35d13537d13e4f7a9f59bb9b610cef413122ad41e1a17ce6dc14ad7fa08724d89cb3c408fd769151fb7b5490e357f7c6d4122ad21481f48f2740f21d223a2",
"jwt_key": "6530e8ae1117846a5b8493bd445b8773d588727d324faba05a1c596f2762cb97e2141aa00a32cddce245d95101fc0495301e0fe7043ddf4e1216c703e27107a4",
"last_used_at": "2023-01-04T03:24:48.171640+00:00",
"last_used_ip": "172.18.0.1",
"credential_id": "711894da0c83415095b3a6314ff20d86",
"version": "2022.12.9"
},
{
"id": "784682c5d4e94733b2e2337f383ecca5",
"user_id": "e85fc7b7b8924dc9b024ce90ad23799e",
"client_id": null,
"client_name": "Test token",
"client_icon": null,
"token_type": "long_lived_access_token",
"created_at": "2023-01-04T02:50:30.713023+00:00",
"access_token_expiration": 315360000.0,
"token": "af2df45d0d604b82f0f00191eb368e94c518ba5b2cb883bb194d0353e7443a54ce355155730a61f586e3822b6422ccf32d8d5bb7243ae8b9633c747210e1bcc6",
"jwt_key": "60e732981c154d30daa2ad2eb26763e03d9b5687a8100d7fdcff0f4a7f5b046a0968cbf6a4d0e850528fedaa73b2ef76952b049adc293eeb35db670801ccc2d7",
"last_used_at": "2023-01-04T02:50:30.713300+00:00",
"token": "340c75a47a7517d263ac4860683b6c9841f9593b9649fd379c82f257f4f6f809a0a636868cb606ca6163c533f1efdb294c4f50a2efde4a36db23967caa144121",
"jwt_key": "fdeaf63844d1b702572ce014db18ff05074e775f04460ea5674653cee999b7fc0733f9eb99c835b7d6e6317e84bf418c21fcf2ceb65060675782be333896e135",
"last_used_at": null,
"last_used_ip": null,
"credential_id": null,
"version": "2022.12.9"
Expand Down
8 changes: 4 additions & 4 deletions volumes/config/.storage/core.restore_state
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
"user_id": "e85fc7b7b8924dc9b024ce90ad23799e",
"friendly_name": "Test User"
},
"last_changed": "2023-01-04T03:30:21.598752+00:00",
"last_updated": "2023-01-04T03:30:22.797226+00:00",
"last_changed": "2023-01-04T18:45:30.356493+00:00",
"last_updated": "2023-01-04T18:45:31.967822+00:00",
"context": {
"id": "01GNXD8XYDA641MAPS54KF6E86",
"id": "01GNZ1MM5Z604R9V6FBV9RZ6FM",
"parent_id": null,
"user_id": null
}
},
"extra_data": null,
"last_seen": "2023-01-04T03:33:07.052768+00:00"
"last_seen": "2023-01-04T18:46:37.069782+00:00"
}
]
}
4 changes: 2 additions & 2 deletions volumes/config/.storage/http
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"127.0.0.1"
],
"use_x_forwarded_for": true,
"server_port": 8123,
"ssl_profile": "modern",
"cors_allowed_origins": [
"https://cast.home-assistant.io"
],
"ssl_profile": "modern",
"login_attempts_threshold": -1,
"server_port": 8123,
"ip_ban_enabled": true
}
}
2 changes: 1 addition & 1 deletion volumes/config/.storage/http.auth
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"minor_version": 1,
"key": "http.auth",
"data": {
"content_user": "4e4db1b7ae354d6388848e744e900be3"
"content_user": "6ebcf011775a47c1bc279a1777a1e5a7"
}
}

0 comments on commit b8e0688

Please sign in to comment.