twist-innovation-api 0.0.6__tar.gz → 0.0.8__tar.gz

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.
Files changed (24) hide show
  1. {twist_innovation_api-0.0.6/twist_innovation_api.egg-info → twist_innovation_api-0.0.8}/PKG-INFO +1 -1
  2. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/setup.py +1 -1
  3. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistAPI.py +21 -15
  4. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistModel.py +5 -14
  5. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8/twist_innovation_api.egg-info}/PKG-INFO +1 -1
  6. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/LICENSE +0 -0
  7. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/README.md +0 -0
  8. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/pyproject.toml +0 -0
  9. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/setup.cfg +0 -0
  10. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/BackendAdapter.py +0 -0
  11. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistBinarySensor.py +0 -0
  12. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistButton.py +0 -0
  13. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistDevice.py +0 -0
  14. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistGarage.py +0 -0
  15. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistLight.py +0 -0
  16. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistRelay.py +0 -0
  17. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistRgb.py +0 -0
  18. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistSensor.py +0 -0
  19. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistShutter.py +0 -0
  20. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/TwistTypes.py +0 -0
  21. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist/__init__.py +0 -0
  22. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist_innovation_api.egg-info/SOURCES.txt +0 -0
  23. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist_innovation_api.egg-info/dependency_links.txt +0 -0
  24. {twist_innovation_api-0.0.6 → twist_innovation_api-0.0.8}/twist_innovation_api.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twist_innovation_api
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: Python library to talk to the twist-innovation api
5
5
  Home-page: https://github.com/twist-innovation/twist-innovation-api
6
6
  Author: Sibrecht Goudsmedt
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="twist_innovation_api",
5
- version="0.0.6",
5
+ version="0.0.8",
6
6
  packages=find_packages(),
7
7
  install_requires=[
8
8
  # "requests" # For REST API
@@ -43,27 +43,27 @@ class TwistAPI:
43
43
  self.installation_id: Optional[int] = None
44
44
 
45
45
  # Backend adapter for fetching device info
46
- self._backend_adapter = BackendAdapter(backend_url, api_key, installation_uuid)
46
+ self._backend_adapter = BackendAdapter(
47
+ backend_url, api_key, installation_uuid)
47
48
 
48
- async def add_mqtt(self, publisher, subscriber):
49
+ def set_mqtt_publish(self, publisher):
50
+ """Set MQTT publish function so entities can send messages during registration."""
49
51
  self._ext_publish = publisher
50
- self._subscribe = subscriber
51
52
 
53
+ async def set_mqtt_subscribe(self, subscriber):
54
+ """Set MQTT subscribe function and start receiving messages."""
55
+ self._subscribe = subscriber
52
56
  await self._subscribe(f"v2/{self.installation_id}/rx/#", self._on_message_received)
53
57
 
58
+ async def add_mqtt(self, publisher, subscriber):
59
+ """Legacy method for backward compatibility - sets both publish and subscribe."""
60
+ self.set_mqtt_publish(publisher)
61
+ await self.set_mqtt_subscribe(subscriber)
62
+
54
63
  async def get_models(self):
55
64
  """
56
65
  Get models from backend
57
66
 
58
- Returns:
59
- List of TwistModel objects
60
- """
61
- return await self._get_models_from_backend()
62
-
63
- async def _get_models_from_backend(self):
64
- """
65
- Fetch devices from backend and create model list
66
-
67
67
  Returns:
68
68
  List of TwistModel objects
69
69
  """
@@ -90,7 +90,8 @@ class TwistAPI:
90
90
  infos.sort(key=lambda x: x.model_id)
91
91
 
92
92
  # Create device if it doesn't exist
93
- device = next((d for d in self.device_list if d.twist_id == device_id), None)
93
+ device = next(
94
+ (d for d in self.device_list if d.twist_id == device_id), None)
94
95
  if device is None:
95
96
  device = TwistDevice(device_id, 0, self)
96
97
  self.device_list.append(device)
@@ -102,7 +103,8 @@ class TwistAPI:
102
103
  # Get product info if available using deviceAllocationModelKey
103
104
  product_info = None
104
105
  if info.device_allocation_model_key:
105
- product_info = products.get(info.device_allocation_model_key)
106
+ product_info = products.get(
107
+ info.device_allocation_model_key)
106
108
 
107
109
  if product_info:
108
110
  model.product_name = product_info.product_name
@@ -137,6 +139,9 @@ class TwistAPI:
137
139
  async def activate_event(self, model: TwistModel, data: json):
138
140
  await self._publish(model.parent_device.twist_id, "activate_event", data, model.model_id)
139
141
 
142
+ async def request_context(self, model: TwistModel):
143
+ await self._publish(model.parent_device.twist_id, "context", model_id=model.model_id)
144
+
140
145
  def _parse_topic(self, topic):
141
146
  tpc_delim = topic.split('/')
142
147
 
@@ -157,7 +162,8 @@ class TwistAPI:
157
162
  await self.function_map[data["opcode"]](data["twist_id"], payload, data["model_id"])
158
163
 
159
164
  async def _context_msg(self, twist_id, payload, model_id):
160
- device = next((d for d in self.device_list if d.twist_id == twist_id), None)
165
+ device = next(
166
+ (d for d in self.device_list if d.twist_id == twist_id), None)
161
167
  await device.context_msg(model_id, payload)
162
168
 
163
169
  async def _get_board(self, twist_id, payload, model_id=None):
@@ -37,7 +37,8 @@ class TwistModel():
37
37
  "prio": None
38
38
  }
39
39
 
40
- self._update_callback: Callable[[TwistModel], Awaitable[None]] | None = None
40
+ self._update_callback: Callable[[
41
+ TwistModel], Awaitable[None]] | None = None
41
42
 
42
43
  @property
43
44
  def friendly_name(self) -> str:
@@ -54,11 +55,9 @@ class TwistModel():
54
55
  # Replace underscores with spaces and capitalize first letter
55
56
  return self.name.replace('_', ' ').capitalize()
56
57
 
57
-
58
58
  def print_context(self):
59
59
  print("function is not supported")
60
60
 
61
-
62
61
  def parse_general_context(self, payload: str):
63
62
  data = json.loads(payload)
64
63
 
@@ -76,42 +75,34 @@ class TwistModel():
76
75
  self.errors["prio"] = value
77
76
  return data
78
77
 
79
-
80
78
  def _get_value_from_context(self, ctx: dict):
81
79
  return ctx["i"], ctx["vl"]
82
80
 
83
-
84
81
  async def context_msg(self, payload):
85
82
  raise NotImplementedError("Function not supported for this model")
86
83
 
87
-
88
84
  async def turn_on(self):
89
85
  raise NotImplementedError("Function not supported for this model")
90
86
 
91
-
92
87
  async def turn_off(self):
93
88
  raise NotImplementedError("Function not supported for this model")
94
89
 
95
-
96
90
  async def open(self):
97
91
  raise NotImplementedError("Function not supported for this model")
98
92
 
99
-
100
93
  async def stop(self):
101
94
  raise NotImplementedError("Function not supported for this model")
102
95
 
103
-
104
96
  async def close(self):
105
97
  raise NotImplementedError("Function not supported for this model")
106
98
 
107
-
108
99
  async def toggle(self):
109
100
  raise NotImplementedError("Function not supported for this model")
110
101
 
111
-
112
102
  async def set_value(self, value: int | list[int, int] | list[int, int, int], fading_time: int | None = None):
113
103
  raise NotImplementedError("Function not supported for this model")
114
104
 
115
-
116
- def register_update_cb(self, cb: Callable[[TwistModel], Awaitable[None]]):
105
+ async def register_update_cb(self, cb: Callable[[TwistModel], Awaitable[None]]):
117
106
  self._update_callback = cb
107
+
108
+ await self.parent_device.api.request_context(self)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twist_innovation_api
3
- Version: 0.0.6
3
+ Version: 0.0.8
4
4
  Summary: Python library to talk to the twist-innovation api
5
5
  Home-page: https://github.com/twist-innovation/twist-innovation-api
6
6
  Author: Sibrecht Goudsmedt