HomeAssistant-API 3.0.2__py3-none-any.whl → 3.0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- homeassistant_api/_async/models/domains.py +29 -4
- homeassistant_api/py.typed +0 -0
- homeassistant_api/rawapi.py +9 -14
- homeassistant_api/rawclient.py +2 -2
- {homeassistant_api-3.0.2.dist-info → homeassistant_api-3.0.3.dist-info}/METADATA +3 -6
- {homeassistant_api-3.0.2.dist-info → homeassistant_api-3.0.3.dist-info}/RECORD +8 -7
- {homeassistant_api-3.0.2.dist-info → homeassistant_api-3.0.3.dist-info}/LICENSE +0 -0
- {homeassistant_api-3.0.2.dist-info → homeassistant_api-3.0.3.dist-info}/WHEEL +0 -0
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
"""File for Service and Domain data models"""
|
|
2
2
|
|
|
3
|
-
from typing import Any, Dict, Tuple, cast
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Dict, Optional, Tuple, cast
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from pydantic import BaseModel, Field
|
|
6
6
|
|
|
7
|
+
from ...models import State
|
|
8
|
+
from ...models.domains import ServiceField
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from homeassistant_api import Client
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AsyncDomain(BaseModel):
|
|
9
15
|
"""A class representing the domain that services belong to."""
|
|
10
16
|
|
|
17
|
+
domain_id: str
|
|
18
|
+
client: "Client" = Field(exclude=True, repr=False)
|
|
19
|
+
services: Dict[str, "AsyncService"] = {}
|
|
20
|
+
|
|
11
21
|
def add_service(self, service_id: str, **data) -> None:
|
|
12
22
|
"""Registers services into a domain to be used or accessed"""
|
|
13
23
|
self.services.update(
|
|
@@ -24,10 +34,25 @@ class AsyncDomain(Domain):
|
|
|
24
34
|
"""Return a Service with the given service_id, returns None if no such service exists"""
|
|
25
35
|
return self.services.get(service_id, None)
|
|
26
36
|
|
|
37
|
+
def __getattr__(self, attr: str):
|
|
38
|
+
"""Allows services accessible as attributes"""
|
|
39
|
+
if attr in self.__dict__:
|
|
40
|
+
return super().__getattribute__(attr)
|
|
41
|
+
if attr in self.services:
|
|
42
|
+
return self.get_service(attr)
|
|
43
|
+
return super().__getattribute__(attr)
|
|
27
44
|
|
|
28
|
-
|
|
45
|
+
|
|
46
|
+
class AsyncService(BaseModel):
|
|
29
47
|
"""Class representing services from homeassistant"""
|
|
30
48
|
|
|
49
|
+
service_id: str
|
|
50
|
+
domain: AsyncDomain
|
|
51
|
+
name: Optional[str] = None
|
|
52
|
+
description: Optional[str] = None
|
|
53
|
+
fields: Optional[Dict[str, ServiceField]] = None
|
|
54
|
+
target: Optional[Dict[str, dict]] = None
|
|
55
|
+
|
|
31
56
|
async def async_trigger(self, **service_data) -> Tuple[State, ...]:
|
|
32
57
|
"""Triggers the service associated with this object."""
|
|
33
58
|
data = await self.domain.client.async_trigger_service(
|
|
File without changes
|
homeassistant_api/rawapi.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"""Module for parent RawWrapper class"""
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
|
+
import re
|
|
4
5
|
from datetime import datetime
|
|
5
6
|
from typing import Dict, Optional, Tuple, Union
|
|
6
7
|
|
|
7
8
|
from .const import DATE_FMT
|
|
8
|
-
from .errors import MalformedInputError
|
|
9
9
|
from .models import Entity
|
|
10
10
|
|
|
11
11
|
|
|
@@ -72,16 +72,13 @@ class RawWrapper:
|
|
|
72
72
|
"""Custom method for constructing non-standard query strings"""
|
|
73
73
|
return "&".join([k if v is None else f"{k}={v}" for k, v in params.items()])
|
|
74
74
|
|
|
75
|
-
@
|
|
76
|
-
def
|
|
77
|
-
"""
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
entity_id.lower() == entity_id,
|
|
83
|
-
]
|
|
84
|
-
return True in checks
|
|
75
|
+
@staticmethod
|
|
76
|
+
def format_entity_id(entity_id: str) -> str:
|
|
77
|
+
"""Takes in a string and formats it into valid snake_case."""
|
|
78
|
+
entity_id = re.sub(r"([A-Z]+)([A-Z][a-z])", r"\1_\2", entity_id)
|
|
79
|
+
entity_id = re.sub(r"([a-z\d])([A-Z])", r"\1_\2", entity_id)
|
|
80
|
+
entity_id = entity_id.replace("-", "_")
|
|
81
|
+
return entity_id.lower()
|
|
85
82
|
|
|
86
83
|
def prepare_entity_id(
|
|
87
84
|
self,
|
|
@@ -100,9 +97,7 @@ class RawWrapper:
|
|
|
100
97
|
entity_id = group + "." + slug
|
|
101
98
|
elif entity_id is None:
|
|
102
99
|
raise ValueError("Neither group and slug or entity_id provided.")
|
|
103
|
-
|
|
104
|
-
raise MalformedInputError(f"The entity_id, {entity_id!r}, is malformed")
|
|
105
|
-
return entity_id
|
|
100
|
+
return self.format_entity_id(entity_id)
|
|
106
101
|
|
|
107
102
|
@staticmethod
|
|
108
103
|
def prepare_get_entity_histories_params(
|
homeassistant_api/rawclient.py
CHANGED
|
@@ -237,8 +237,8 @@ class RawClient(RawWrapper, JsonProcessingMixin):
|
|
|
237
237
|
**payload,
|
|
238
238
|
) -> State:
|
|
239
239
|
"""
|
|
240
|
-
|
|
241
|
-
|
|
240
|
+
This method sets the representation of a device within Home Assistant and will not communicate with the actual device.
|
|
241
|
+
To communicate with the device, use :py:meth:`homeassistant_api.Service.trigger` or :py:meth:`homeassistant_api.AsyncService.trigger`
|
|
242
242
|
"""
|
|
243
243
|
entity_id = self.prepare_entity_id(
|
|
244
244
|
group=group,
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: homeassistant-api
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.3
|
|
4
4
|
Summary: Python Wrapper for Homeassistant's REST API
|
|
5
5
|
Home-page: https://github.com/GrandMoff100/HomeAssistantAPI
|
|
6
6
|
License: GPL-3.0-or-later
|
|
7
7
|
Author: GrandMoff100
|
|
8
8
|
Author-email: minecraftcrusher100@gmail.com
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.8,<4.0
|
|
10
10
|
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.8
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.9
|
|
16
15
|
Requires-Dist: aiohttp (>=3.8.1,<4.0.0)
|
|
17
16
|
Requires-Dist: aiohttp-client-cache (>=0.6.1,<0.7.0)
|
|
17
|
+
Requires-Dist: autodoc-pydantic (>=1.6.1,<2.0.0)
|
|
18
18
|
Requires-Dist: pydantic (>=1.9.0,<2.0.0)
|
|
19
19
|
Requires-Dist: requests (>=2.26.0,<3.0.0)
|
|
20
20
|
Requires-Dist: requests-cache (>=0.9.2,<0.10.0)
|
|
@@ -25,7 +25,6 @@ Description-Content-Type: text/markdown
|
|
|
25
25
|
|
|
26
26
|
# HomeassistantAPI
|
|
27
27
|
|
|
28
|
-

|
|
29
28
|
[](https://pypi.org/project/homeassistant_api)
|
|
30
29
|

|
|
31
30
|
[](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)
|
|
@@ -35,8 +34,6 @@ Description-Content-Type: text/markdown
|
|
|
35
34
|
|
|
36
35
|
## Python wrapper for Homeassistant's [REST API](https://developers.home-assistant.io/docs/api/rest/)
|
|
37
36
|
|
|
38
|
-
Please ⭐️ the repo if you find this project useful or cool!
|
|
39
|
-
|
|
40
37
|
Here is a quick example.
|
|
41
38
|
```py
|
|
42
39
|
from homeassistant_api import Client
|
|
@@ -2,7 +2,7 @@ homeassistant_api/__init__.py,sha256=2ytHsy2lmXRF4Sb5f7s8UjkOIvlwC0BAavfqk9Nichs
|
|
|
2
2
|
homeassistant_api/_async/__init__.py,sha256=LIqz76A06Gv8fOtSoh7cavVKfz60oW7UJLCvntfrRKY,188
|
|
3
3
|
homeassistant_api/_async/asyncclient.py,sha256=4nifxyGY98i9KFKSvtJZAiDO67Lxfs5anFUjiPKl9D0,10758
|
|
4
4
|
homeassistant_api/_async/models/__init__.py,sha256=UeSGN4JiY_CkXKA-qL_bV_Xmn50wJoeacf5MbEo0m28,169
|
|
5
|
-
homeassistant_api/_async/models/domains.py,sha256=
|
|
5
|
+
homeassistant_api/_async/models/domains.py,sha256=KGFjXfKJ1z4u-qvsvwa2MSxgbK6fq8oTTvkcsYWF8EU,2123
|
|
6
6
|
homeassistant_api/_async/models/entity.py,sha256=-J1SH0Z9YYI12mFqDJp6GXluQ4Bdqm4xkUWo9VK1JQY,2305
|
|
7
7
|
homeassistant_api/_async/models/events.py,sha256=bs86N92XMJQXJeVzWGz5YkjXH8zLWDzKO2OscFwd5Gk,792
|
|
8
8
|
homeassistant_api/client.py,sha256=L9bWMQKPh0fOyW9USli16JjGODEzqSvkNR3eiZiie1E,225
|
|
@@ -18,9 +18,10 @@ homeassistant_api/models/history.py,sha256=a5HHV7bw4qeFtOYSqpmun98Kx5yV0DesTmLNi
|
|
|
18
18
|
homeassistant_api/models/logbook.py,sha256=Op99ux61IQfcD_0UpdFqkKIl6G3j6mcZEhDJPgWoZUc,377
|
|
19
19
|
homeassistant_api/models/states.py,sha256=60OOGntib5xJndTR6OYR10cZC31dvwPYveNR58rd250,420
|
|
20
20
|
homeassistant_api/processing.py,sha256=quntfsA7ljZCVvd49zuyQ05uYqlfq9t3BLxp809LNWA,4500
|
|
21
|
-
homeassistant_api/
|
|
22
|
-
homeassistant_api/
|
|
23
|
-
homeassistant_api
|
|
24
|
-
homeassistant_api-3.0.
|
|
25
|
-
homeassistant_api-3.0.
|
|
26
|
-
homeassistant_api-3.0.
|
|
21
|
+
homeassistant_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
+
homeassistant_api/rawapi.py,sha256=FKZArAgDuLppLTBFCdl-SI3VfEeA7rkEwhaoL06hoT8,5797
|
|
23
|
+
homeassistant_api/rawclient.py,sha256=HRJzXCMaHaQPyd34gBlhZtWZ20_cc3Ud2p4O2EV1F5I,10143
|
|
24
|
+
homeassistant_api-3.0.3.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
25
|
+
homeassistant_api-3.0.3.dist-info/WHEEL,sha256=DA86_h4QwwzGeRoz62o1svYt5kGEXpoUTuTtwzoTb30,83
|
|
26
|
+
homeassistant_api-3.0.3.dist-info/METADATA,sha256=VyPMTd4pyz0eoQMhZS-ZrfGT1P5xMH9__tZP66ci53o,2945
|
|
27
|
+
homeassistant_api-3.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|