HomeAssistant-API 3.0.2__py3-none-any.whl → 3.0.3.post1__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.
@@ -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 ...models import Domain, Service, State
5
+ from pydantic import BaseModel, Field
6
6
 
7
+ from ...models import State
8
+ from ...models.domains import ServiceField
7
9
 
8
- class AsyncDomain(Domain):
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
- class AsyncService(Service):
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
@@ -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
- @classmethod
76
- def malformed_id(cls, entity_id: str) -> bool:
77
- """Checks whether or not a given entity_id is formatted correctly"""
78
- checks = [
79
- " " in entity_id,
80
- "." not in entity_id,
81
- "-" in entity_id,
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
- if self.malformed_id(entity_id):
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(
@@ -237,8 +237,8 @@ class RawClient(RawWrapper, JsonProcessingMixin):
237
237
  **payload,
238
238
  ) -> State:
239
239
  """
240
- Sets the state of an entity and it does not have to be backed by a real entity.
241
- Returns the new state afterwards.
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,16 +1,15 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: homeassistant-api
3
- Version: 3.0.2
3
+ Version: 3.0.3.post1
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.7,<4.0
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)
@@ -25,7 +24,6 @@ Description-Content-Type: text/markdown
25
24
 
26
25
  # HomeassistantAPI
27
26
 
28
- ![Lines of code](https://img.shields.io/tokei/lines/github/GrandMoff100/HomeassistantAPI?style=for-the-badge)
29
27
  [![PyPI - Downloads](https://img.shields.io/pypi/dm/HomeAssistant-API?style=for-the-badge)](https://pypi.org/project/homeassistant_api)
30
28
  ![GitHub commits since latest release (by date including pre-releases)](https://img.shields.io/github/commits-since/GrandMoff100/HomeassistantAPI/latest/dev?include_prereleases&style=for-the-badge)
31
29
  [![Read the Docs (version)](https://img.shields.io/readthedocs/homeassistantapi?style=for-the-badge)](https://homeassistantapi.readthedocs.io/en/latest/?badge=latest)
@@ -35,8 +33,6 @@ Description-Content-Type: text/markdown
35
33
 
36
34
  ## Python wrapper for Homeassistant's [REST API](https://developers.home-assistant.io/docs/api/rest/)
37
35
 
38
- Please ⭐️ the repo if you find this project useful or cool!
39
-
40
36
  Here is a quick example.
41
37
  ```py
42
38
  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=gb5mIMTY3L1w5VVgRMgSIFXhxtg0Rm8BHGBloldfeOQ,1336
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/rawapi.py,sha256=Zw9lrMXMdEOOHLSaIBJXk7aIWDl_lHwQt4ez6YzRhjo,5912
22
- homeassistant_api/rawclient.py,sha256=9c2Z2UX1UuT58Sm73YzzEDIpg2ChkJcxtgPi5l8W5hk,10004
23
- homeassistant_api-3.0.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
24
- homeassistant_api-3.0.2.dist-info/WHEEL,sha256=DA86_h4QwwzGeRoz62o1svYt5kGEXpoUTuTtwzoTb30,83
25
- homeassistant_api-3.0.2.dist-info/METADATA,sha256=Y4h4rHMukH-VV13suP1Nkra9cAZWlnKyEEHBGNxYQR0,3121
26
- homeassistant_api-3.0.2.dist-info/RECORD,,
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.post1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
25
+ homeassistant_api-3.0.3.post1.dist-info/WHEEL,sha256=DA86_h4QwwzGeRoz62o1svYt5kGEXpoUTuTtwzoTb30,83
26
+ homeassistant_api-3.0.3.post1.dist-info/METADATA,sha256=6kvTutuD5pRTS0hQpOnzpN4SJoO0w7DQYHQQVQMB8ZE,2902
27
+ homeassistant_api-3.0.3.post1.dist-info/RECORD,,