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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
hooks:
- id: trailing-whitespace
rev: "v4.1.0"
rev: "v6.0.0"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.15.6'
rev: 'v0.16.5'
hooks:
- id: ruff-format
- id: ruff-check
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
from homeassistant_api import Client

with Client(
'<API Server URL>', # i.e. 'http://homeassistant.local:8123/api/'
'<Your Long Lived Access-Token>'
"<API Server URL>", # i.e. 'http://homeassistant.local:8123/api/'
"<Your Long Lived Access-Token>",
) as client:
client.trigger_service('light', 'turn_on', entity_id="light.living_room")
client.trigger_service("light", "turn_on", entity_id="light.living_room")
```

All four client classes share the same method names.
Expand All @@ -35,12 +35,14 @@ The async clients (`AsyncClient`, `AsyncWebsocketClient`) use `async def` method
import asyncio
from homeassistant_api import AsyncClient


async def main():
async with AsyncClient(
'<REST API Server URL>', # i.e. 'http://homeassistant.local:8123/api/'
'<Your Long Lived Access-Token>',
"<REST API Server URL>", # i.e. 'http://homeassistant.local:8123/api/'
"<Your Long Lived Access-Token>",
) as client:
await client.trigger_service('light', 'turn_on', entity_id="light.living_room")
await client.trigger_service("light", "turn_on", entity_id="light.living_room")


asyncio.run(main())
```
Expand All @@ -51,10 +53,10 @@ asyncio.run(main())
from homeassistant_api import WebsocketClient

with WebsocketClient(
'<WS API Server URL>', # i.e. 'ws://homeassistant.local:8123/api/websocket'
'<Your Long Lived Access-Token>'
"<WS API Server URL>", # i.e. 'ws://homeassistant.local:8123/api/websocket'
"<Your Long Lived Access-Token>",
) as ws_client:
ws_client.trigger_service('light', 'turn_on', entity_id="light.living_room")
ws_client.trigger_service("light", "turn_on", entity_id="light.living_room")
```

## Documentation
Expand Down
3 changes: 1 addition & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
codecov:
token: 2f0c3d11-6099-4276-a5f0-1ad68499ad26
codecov: {}
4 changes: 1 addition & 3 deletions homeassistant_api/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ def _parse_text(response: ResponseType) -> str:
def _parse_content(response: ResponseType) -> Any:
"""Look up and call the appropriate parser by content-type."""
content_type = response.headers.get("content-type", "text/plain")
if isinstance(content_type, bytes):
content_type = content_type.decode("utf-8") # pragma: no cover
mimetype = str(content_type).split(";")[0].strip().lower()
mimetype = content_type.split(";")[0].strip().lower()

if (parser := _PARSERS.get(mimetype)) is None:
msg = f"No response processor found for mimetype {mimetype!r}."
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = ["hatchling"]

[project]
name = "HomeAssistant-API"
version = "6.0.1"
version = "6.1.0"
description = "Python Wrapper for Homeassistant's REST API"
readme = "README.md"
license = "GPL-3.0-or-later"
Expand Down Expand Up @@ -91,6 +91,7 @@ ignore = [
"FBT",
"TD",
"FIX",
"CPY",
]

[tool.ruff.lint.per-file-ignores]
Expand Down
1 change: 1 addition & 0 deletions tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ def test_trigger_service(cached_client: Client) -> None:
logger.info(resp)
assert isinstance(resp, tuple)


def test_call_service(cached_client: Client) -> None:
"""Tests the `POST /api/services/<domain>/<service>` endpoint."""
notify = cached_client.get_domain("notify")
Expand Down
Loading