python-mystrom 2.2.0__tar.gz → 2.4.0__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 (28) hide show
  1. {python-mystrom-2.2.0 → python_mystrom-2.4.0}/LICENSE +1 -1
  2. {python-mystrom-2.2.0/python_mystrom.egg-info → python_mystrom-2.4.0}/PKG-INFO +16 -15
  3. {python-mystrom-2.2.0 → python_mystrom-2.4.0}/pymystrom/__init__.py +11 -11
  4. {python-mystrom-2.2.0 → python_mystrom-2.4.0}/pymystrom/bulb.py +5 -4
  5. {python-mystrom-2.2.0 → python_mystrom-2.4.0}/pymystrom/cli.py +1 -0
  6. python_mystrom-2.4.0/pymystrom/device_types.py +33 -0
  7. {python-mystrom-2.2.0 → python_mystrom-2.4.0}/pymystrom/discovery.py +5 -14
  8. {python-mystrom-2.2.0 → python_mystrom-2.4.0}/pymystrom/pir.py +3 -1
  9. {python-mystrom-2.2.0 → python_mystrom-2.4.0}/pymystrom/switch.py +54 -7
  10. python_mystrom-2.4.0/pyproject.toml +26 -0
  11. python-mystrom-2.2.0/MANIFEST.in +0 -2
  12. python-mystrom-2.2.0/PKG-INFO +0 -274
  13. python-mystrom-2.2.0/examples/example-bulb-hsv.py +0 -18
  14. python-mystrom-2.2.0/examples/example-bulb.py +0 -72
  15. python-mystrom-2.2.0/examples/example-discovery.py +0 -13
  16. python-mystrom-2.2.0/examples/example-get-data-bulb.py +0 -12
  17. python-mystrom-2.2.0/examples/example-pir.py +0 -42
  18. python-mystrom-2.2.0/examples/example-switch.py +0 -36
  19. python-mystrom-2.2.0/python_mystrom.egg-info/SOURCES.txt +0 -24
  20. python-mystrom-2.2.0/python_mystrom.egg-info/dependency_links.txt +0 -1
  21. python-mystrom-2.2.0/python_mystrom.egg-info/entry_points.txt +0 -2
  22. python-mystrom-2.2.0/python_mystrom.egg-info/requires.txt +0 -4
  23. python-mystrom-2.2.0/python_mystrom.egg-info/top_level.txt +0 -1
  24. python-mystrom-2.2.0/python_mystrom.egg-info/zip-safe +0 -1
  25. python-mystrom-2.2.0/setup.cfg +0 -4
  26. python-mystrom-2.2.0/setup.py +0 -48
  27. {python-mystrom-2.2.0 → python_mystrom-2.4.0}/README.rst +0 -0
  28. {python-mystrom-2.2.0 → python_mystrom-2.4.0}/pymystrom/exceptions.py +0 -0
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2023 Fabian Affolter <fabian@affolter-engineering.ch>
3
+ Copyright (c) 2015-2025 Fabian Affolter <fabian@affolter-engineering.ch>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,23 +1,23 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: python-mystrom
3
- Version: 2.2.0
3
+ Version: 2.4.0
4
4
  Summary: Asynchronous Python API client for interacting with myStrom devices
5
- Home-page: https://github.com/home-assistant-ecosystem/python-mystrom
5
+ License: MIT
6
+ Keywords: myStrom,API,client,asynchronous
6
7
  Author: Fabian Affolter
7
8
  Author-email: fabian@affolter-engineering.ch
8
- License: MIT
9
- Classifier: Development Status :: 3 - Alpha
10
- Classifier: Environment :: Console
11
- Classifier: Intended Audience :: Developers
9
+ Requires-Python: >=3.11
12
10
  Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: MacOS :: MacOS X
14
- Classifier: Operating System :: Microsoft :: Windows
15
- Classifier: Operating System :: POSIX
16
- Classifier: Programming Language :: Python :: 3.9
17
- Classifier: Programming Language :: Python :: 3.10
18
- Classifier: Topic :: Utilities
19
- Requires-Python: >=3.9
20
- License-File: LICENSE
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Dist: aiohttp
16
+ Requires-Dist: click
17
+ Requires-Dist: requests
18
+ Project-URL: Homepage, https://github.com/home-assistant-ecosystem/python-mystrom
19
+ Project-URL: Repository, https://github.com/home-assistant-ecosystem/python-mystrom
20
+ Description-Content-Type: text/x-rst
21
21
 
22
22
  python-mystrom |License| |PyPI|
23
23
  ===================================
@@ -272,3 +272,4 @@ License
272
272
  .. |PyPI| image:: https://img.shields.io/pypi/v/python-mystrom.svg
273
273
  :target: https://pypi.python.org/pypi/python-mystrom
274
274
  :alt: PyPI release
275
+
@@ -1,18 +1,16 @@
1
1
  """Base details for the myStrom Python bindings."""
2
+
2
3
  import asyncio
3
- import aiohttp
4
- import async_timeout
5
- from yarl import URL
6
- from typing import Any, Mapping, Optional
7
4
  import socket
8
- from .exceptions import MyStromConnectionError
5
+ from typing import Any, Mapping, Optional
9
6
 
10
- import pkg_resources
7
+ import aiohttp
8
+ from yarl import URL
11
9
 
12
- __version__ = pkg_resources.get_distribution("setuptools").version
10
+ from .exceptions import MyStromConnectionError
13
11
 
14
12
  TIMEOUT = 10
15
- USER_AGENT = f"PythonMyStrom/{__version__}"
13
+ USER_AGENT = "PythonMyStrom/1.0"
16
14
 
17
15
 
18
16
  async def _request(
@@ -34,15 +32,17 @@ async def _request(
34
32
  self._close_session = True
35
33
 
36
34
  try:
37
- with async_timeout.timeout(TIMEOUT):
38
- response = await self._session.request(
35
+ response = await asyncio.wait_for(
36
+ self._session.request(
39
37
  method,
40
38
  uri,
41
39
  data=data,
42
40
  json=json_data,
43
41
  params=params,
44
42
  headers=headers,
45
- )
43
+ ),
44
+ timeout=TIMEOUT,
45
+ )
46
46
  except asyncio.TimeoutError as exception:
47
47
  raise MyStromConnectionError(
48
48
  "Timeout occurred while connecting to myStrom device."
@@ -1,10 +1,11 @@
1
1
  """Support for communicating with myStrom bulbs."""
2
+
2
3
  import asyncio
3
4
  import logging
5
+ from typing import Optional
4
6
 
5
7
  import aiohttp
6
8
  from yarl import URL
7
- from typing import Any, Dict, Iterable, List, Optional, Union
8
9
 
9
10
  from . import _request as request
10
11
 
@@ -21,7 +22,7 @@ class MyStromBulb:
21
22
  host: str,
22
23
  mac: str,
23
24
  session: aiohttp.client.ClientSession = None,
24
- ):
25
+ ) -> None:
25
26
  """Initialize the bulb."""
26
27
  self._close_session = False
27
28
  self._host = host
@@ -38,7 +39,7 @@ class MyStromBulb:
38
39
  self._transition_time = 0
39
40
  self.uri = URL.build(scheme="http", host=self._host).join(URI_BULB) / self._mac
40
41
 
41
- async def get_state(self) -> object:
42
+ async def get_state(self) -> None:
42
43
  """Get the state of the bulb."""
43
44
  response = await request(self, uri=self.uri)
44
45
  self._consumption = response[self._mac]["power"]
@@ -55,7 +56,7 @@ class MyStromBulb:
55
56
  return self._firmware
56
57
 
57
58
  @property
58
- def mac(self) -> float:
59
+ def mac(self) -> str:
59
60
  """Return the MAC address."""
60
61
  return self._mac
61
62
 
@@ -1,4 +1,5 @@
1
1
  """Command-line tool for working with myStrom devices."""
2
+
2
3
  import click
3
4
  import requests
4
5
  import asyncio
@@ -0,0 +1,33 @@
1
+ """
2
+ Device types.
3
+
4
+ See https://api.mystrom.ch/#f37a4be7-0233-4d93-915e-c6f92656f129
5
+ """
6
+
7
+ DEVICE_MAPPING_NUMERIC = {
8
+ 101: "Switch CH v1",
9
+ 102: "Bulb",
10
+ 103: "Button+",
11
+ 104: "Button",
12
+ 105: "LED Strip",
13
+ 106: "Switch CH v2",
14
+ 107: "Switch EU",
15
+ 110: "Motion Sensor",
16
+ 113: "modulo® STECCO / CUBO",
17
+ 118: "Button Plus 2nd",
18
+ 120: "Switch Zero",
19
+ }
20
+
21
+ DEVICE_MAPPING_LITERAL = {
22
+ "WSW": DEVICE_MAPPING_NUMERIC[101],
23
+ "WRB": DEVICE_MAPPING_NUMERIC[102],
24
+ "WBP": DEVICE_MAPPING_NUMERIC[103],
25
+ "WBS": DEVICE_MAPPING_NUMERIC[104],
26
+ "WRS": DEVICE_MAPPING_NUMERIC[105],
27
+ "WS2": DEVICE_MAPPING_NUMERIC[106],
28
+ "WSE": DEVICE_MAPPING_NUMERIC[107],
29
+ "WMS": DEVICE_MAPPING_NUMERIC[110],
30
+ "WLL": DEVICE_MAPPING_NUMERIC[113],
31
+ "BP2": DEVICE_MAPPING_NUMERIC[118],
32
+ "LCS": DEVICE_MAPPING_NUMERIC[120],
33
+ }
@@ -1,21 +1,12 @@
1
1
  """Support for discovering myStrom devices."""
2
+
2
3
  import asyncio
3
4
  import logging
4
- from typing import Optional, List
5
+ from typing import List, Optional
5
6
 
6
- _LOGGER = logging.getLogger(__name__)
7
+ from .device_types import DEVICE_MAPPING_NUMERIC
7
8
 
8
- DEVICE_MAPPING = {
9
- "101": "myStrom Switch v1",
10
- "102": "myStrom Bulb",
11
- "103": "myStrom Button+",
12
- "104": "myStrom Button",
13
- "105": "myStrom LED strip",
14
- "106": "myStzrom Switch v2",
15
- "107": "myStrom Switch EU",
16
- "110": "myStrom Motion sensor",
17
- "120": "myStrom Switch Zero",
18
- }
9
+ _LOGGER = logging.getLogger(__name__)
19
10
 
20
11
 
21
12
  class DiscoveredDevice(object):
@@ -39,7 +30,7 @@ class DiscoveredDevice(object):
39
30
  device.type = announce_msg[6]
40
31
 
41
32
  if device.type == "102":
42
- device.hardware = DEVICE_MAPPING[str(announce_msg[6])]
33
+ device.hardware = DEVICE_MAPPING_NUMERIC[int(announce_msg[6])]
43
34
  else:
44
35
  device.hardware = "non_mystrom"
45
36
  status = announce_msg[7]
@@ -1,7 +1,9 @@
1
1
  """Support for communicating with myStrom PIRs."""
2
+
3
+ from typing import Any, Dict, Iterable, List, Optional, Union
4
+
2
5
  import aiohttp
3
6
  from yarl import URL
4
- from typing import Any, Dict, Iterable, List, Optional, Union
5
7
 
6
8
  from . import _request as request
7
9
 
@@ -1,9 +1,12 @@
1
1
  """Support for communicating with myStrom plugs/switches."""
2
+
3
+ from typing import Optional, Union
4
+
2
5
  import aiohttp
3
6
  from yarl import URL
4
- from typing import Any, Dict, Iterable, List, Optional, Union
5
7
 
6
8
  from . import _request as request
9
+ from .device_types import DEVICE_MAPPING_LITERAL, DEVICE_MAPPING_NUMERIC
7
10
 
8
11
 
9
12
  class MyStromSwitch:
@@ -16,10 +19,14 @@ class MyStromSwitch:
16
19
  self._session = session
17
20
  self._consumption = 0
18
21
  self._consumedWs = 0
22
+ self._boot_id = None
23
+ self._energy_since_boot = None
24
+ self._time_since_boot = None
19
25
  self._state = None
20
26
  self._temperature = None
21
27
  self._firmware = None
22
28
  self._mac = None
29
+ self._device_type: Optional[Union[str, int]] = None
23
30
  self.uri = URL.build(scheme="http", host=self._host)
24
31
 
25
32
  async def turn_on(self) -> None:
@@ -54,6 +61,18 @@ class MyStromSwitch:
54
61
  self._consumedWs = response["Ws"]
55
62
  except KeyError:
56
63
  self._consumedWs = None
64
+ try:
65
+ self._boot_id = response["boot_id"]
66
+ except KeyError:
67
+ self._boot_id = None
68
+ try:
69
+ self._energy_since_boot = response["energy_since_boot"]
70
+ except KeyError:
71
+ self._energy_since_boot = None
72
+ try:
73
+ self._time_since_boot = response["time_since_boot"]
74
+ except KeyError:
75
+ self._time_since_boot = None
57
76
  self._state = response["relay"]
58
77
  try:
59
78
  self._temperature = response["temperature"]
@@ -70,6 +89,16 @@ class MyStromSwitch:
70
89
 
71
90
  self._firmware = response["version"]
72
91
  self._mac = response["mac"]
92
+ self._device_type = response["type"]
93
+
94
+ @property
95
+ def device_type(self) -> Optional[str]:
96
+ """Return the device type as string (e.g. "Switch CH v1" or "Button+")."""
97
+ if isinstance(self._device_type, int):
98
+ return DEVICE_MAPPING_NUMERIC.get(self._device_type)
99
+ elif isinstance(self._device_type, str):
100
+ return DEVICE_MAPPING_LITERAL.get(self._device_type)
101
+ return None
73
102
 
74
103
  @property
75
104
  def relay(self) -> bool:
@@ -77,7 +106,7 @@ class MyStromSwitch:
77
106
  return bool(self._state)
78
107
 
79
108
  @property
80
- def consumption(self) -> float:
109
+ def consumption(self) -> Optional[float]:
81
110
  """Return the current power consumption in mWh."""
82
111
  if self._consumption is not None:
83
112
  return round(self._consumption, 1)
@@ -85,7 +114,7 @@ class MyStromSwitch:
85
114
  return self._consumption
86
115
 
87
116
  @property
88
- def consumedWs(self) -> float:
117
+ def consumedWs(self) -> Optional[float]:
89
118
  """The average of energy consumed per second since last report call."""
90
119
  if self._consumedWs is not None:
91
120
  return round(self._consumedWs, 1)
@@ -93,18 +122,36 @@ class MyStromSwitch:
93
122
  return self._consumedWs
94
123
 
95
124
  @property
96
- def firmware(self) -> float:
125
+ def boot_id(self) -> Optional[str]:
126
+ """A unique identifier to distinguish whether the energy counter has been reset."""
127
+ return self._boot_id
128
+
129
+ @property
130
+ def energy_since_boot(self) -> Optional[float]:
131
+ """The total energy in watt seconds (Ws) that has been measured since the last power-up or restart of the device."""
132
+ if self._energy_since_boot is not None:
133
+ return round(self._energy_since_boot, 2)
134
+
135
+ return self._energy_since_boot
136
+
137
+ @property
138
+ def time_since_boot(self) -> Optional[int]:
139
+ """The time in seconds that has elapsed since the last start or restart of the device."""
140
+ return self._time_since_boot
141
+
142
+ @property
143
+ def firmware(self) -> Optional[str]:
97
144
  """Return the current firmware."""
98
145
  return self._firmware
99
146
 
100
147
  @property
101
- def mac(self) -> float:
148
+ def mac(self) -> Optional[str]:
102
149
  """Return the MAC address."""
103
150
  return self._mac
104
151
 
105
152
  @property
106
- def temperature(self) -> float:
107
- """Return the current temperature in celsius."""
153
+ def temperature(self) -> Optional[float]:
154
+ """Return the current temperature in Celsius."""
108
155
  if self._temperature is not None:
109
156
  return round(self._temperature, 1)
110
157
 
@@ -0,0 +1,26 @@
1
+ [tool.poetry]
2
+ name = "python-mystrom"
3
+ version = "2.4.0"
4
+ description = "Asynchronous Python API client for interacting with myStrom devices"
5
+ authors = ["Fabian Affolter <fabian@affolter-engineering.ch>"]
6
+ license = "MIT"
7
+ readme = "README.rst"
8
+ homepage = "https://github.com/home-assistant-ecosystem/python-mystrom"
9
+ repository = "https://github.com/home-assistant-ecosystem/python-mystrom"
10
+ keywords = ["myStrom", "API", "client", "asynchronous"]
11
+ packages = [
12
+ { include = "pymystrom" }
13
+ ]
14
+
15
+ [tool.poetry.dependencies]
16
+ python = ">=3.11"
17
+ aiohttp = "*"
18
+ click = "*"
19
+ requests = "*"
20
+
21
+ [build-system]
22
+ requires = ["poetry-core>=1.0.0"]
23
+ build-backend = "poetry.core.masonry.api"
24
+
25
+ [tool.poetry.scripts]
26
+ pymystrom = "pymystrom.cli:main"
@@ -1,2 +0,0 @@
1
- include LICENSE CHANGELOG.rst
2
- graft examples
@@ -1,274 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: python-mystrom
3
- Version: 2.2.0
4
- Summary: Asynchronous Python API client for interacting with myStrom devices
5
- Home-page: https://github.com/home-assistant-ecosystem/python-mystrom
6
- Author: Fabian Affolter
7
- Author-email: fabian@affolter-engineering.ch
8
- License: MIT
9
- Classifier: Development Status :: 3 - Alpha
10
- Classifier: Environment :: Console
11
- Classifier: Intended Audience :: Developers
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: MacOS :: MacOS X
14
- Classifier: Operating System :: Microsoft :: Windows
15
- Classifier: Operating System :: POSIX
16
- Classifier: Programming Language :: Python :: 3.9
17
- Classifier: Programming Language :: Python :: 3.10
18
- Classifier: Topic :: Utilities
19
- Requires-Python: >=3.9
20
- License-File: LICENSE
21
-
22
- python-mystrom |License| |PyPI|
23
- ===================================
24
-
25
- Asynchronous Python API client for interacting with `myStrom <https://mystrom.ch>`_
26
- devices.
27
-
28
- This module is not official, developed, supported or endorsed by myStrom AG.
29
- For questions and other inquiries, use the issue tracker in this repo please.
30
-
31
- Without the support of myStrom AG it would have taken much longer to create
32
- this module which is the base for the integration into
33
- `Home Assistant <https://home-assistant.io>`_. myStrom AG has provided hardware.
34
- Their continuous support make further development of this module possible.
35
-
36
- Requirements
37
- ------------
38
-
39
- You need to have `Python <https://www.python.org>`_ installed.
40
-
41
- - `myStrom <https://mystrom.ch>`_ device (bulb, plug or button)
42
- - The ``python-mystrom`` requirements
43
- - Network connection
44
- - Devices connected to your network
45
-
46
- Installation
47
- ------------
48
-
49
- The package is available in the `Python Package Index <https://pypi.python.org/>`_ .
50
-
51
- .. code:: bash
52
-
53
- $ pip3 install python-mystrom
54
-
55
- On a Fedora-based system or on a CentOS/RHEL machine which has EPEL enabled.
56
-
57
- .. code:: bash
58
-
59
- $ sudo dnf -y install python3-mystrom
60
-
61
- For Nix or NixOS users is a package available. Keep in mind that the lastest releases might only
62
- be present in the ``unstable`` channel.
63
-
64
- .. code:: bash
65
-
66
- $ nix-env -iA nixos.python3Packages.python-mystrom
67
-
68
-
69
- Plug/switch
70
- -----------
71
-
72
- At the moment the following endpoints are covered according `https://api.mystrom.ch <https://api.mystrom.ch>`_:
73
-
74
- - ``/report``: for getting the current state and the power consumption
75
- - ``/relay``: for setting the relay state
76
-
77
- You will still be able to use your device with the smartphone application,
78
- ``curl`` or other tools. The samples below shows how to use the switch with
79
- ``httpie`` and ``curl`` along with ``python-mystrom``.
80
-
81
- .. code:: bash
82
-
83
- $ http http://IP_ADDRESS_PLUG/report
84
- HTTP/1.1 200 OK
85
- Content-Length: 39
86
- Content-Type: application/json
87
- Date: Mon, 15 Feb 2016 17:52:21 GMT
88
-
89
- {
90
- "power": 51.630947,
91
- "relay": true
92
- }
93
-
94
- .. code:: bash
95
-
96
- $ curl -X GET http://IP_ADDRESS_PLUG/relay?state=1
97
-
98
-
99
- Bulb
100
- ----
101
-
102
- If the bulb is on then you should be able to retrieve the current state of
103
- the bulb.
104
-
105
- Browse to http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB or use a
106
- command-line tool.
107
-
108
- .. code:: bash
109
-
110
- $ curl -d "color=0;0;100" -d "action=on" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB
111
- {
112
- "5DFF7FAHZ987": {
113
- "on": true,
114
- "color": "0;0;100",
115
- "mode": "hsv",
116
- "ramp": 100,
117
- "notifyurl": ""
118
- }
119
- }
120
-
121
- The bulbs are not able to handle payload formatted as JSON. It's required to
122
- use ``application/x-www-form-urlencoded``. Keep that in mind if something is
123
- not working, especially around setting the color with HSV.
124
-
125
- If you are planning to use your bulbs with `Home Assistant <https://home-assistant.io>`_
126
- set the bulb to a state from `Colors` with the app or use the command below.
127
-
128
- .. code:: bash
129
-
130
- $ curl -d "color=0;0;100" IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB
131
-
132
-
133
- Set State
134
- `````````
135
-
136
- You can set the state with a POST request and a payload.
137
-
138
- - **on**: ``curl -d "action=on" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
139
- - **off**: ``curl -d "action=off" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
140
- - **toggle**: ``$ curl -d "action=toggle" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
141
-
142
- Set Color RGB
143
- `````````````
144
-
145
- One of the supported modes for setting the color is **RBG**.
146
-
147
- - **white**: ``$ curl -d "color=FF000000" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
148
- - **red**: ``$ curl -d "color=00FF0000" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
149
- - **green**: ``$ curl -d "color=0000FF00" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
150
- - **blue**: ``$ curl -d "color=000000FF" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB``
151
-
152
- Set Color HSV (Hue, Saturation, Value)
153
- ``````````````````````````````````````
154
-
155
- It's also possible to use **HSV**.
156
-
157
- .. code:: bash
158
-
159
- $ curl -d "color=0;0;100" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB
160
-
161
- While "color=" is composed with hue, saturation, and value.
162
-
163
- Set Mono (white)
164
- ````````````````
165
-
166
- If you only want to set the "white" color of the bulb, use **mono**.
167
-
168
- .. code:: bash
169
-
170
- $ curl -d "color=10;100" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB
171
-
172
- "color=" contains the value for the color temperature (from 1 to 18) and the
173
- brightness (from 0 to 100).
174
-
175
- Dimming (ramp)
176
- ``````````````
177
-
178
- Add **ramp** and an interval to set up the transition time while changing
179
- colors.
180
-
181
- .. code:: bash
182
-
183
- $ curl -d "action=on&ramp=1000&color=00FF0000" http://IP_ADDRESS_BULB/api/v1/device/MAC_ADDRESS_BULB
184
-
185
- The unit of measurement for ramp is milliseconds (ms).
186
-
187
- Button
188
- ------
189
-
190
- The buttons can be set with the myStrom app or directly via HTTP requests.
191
-
192
- To set the configuration the payload must contains the relevant details for
193
- the actions:
194
-
195
- ``$ curl -v -d "single=<url>&double=<url>&long=<url>&touch=<url>" http://IP_ADDRESS_BUTTON/api/v1/device/MAC_ADDRESS_BUTTON``
196
-
197
- Available actions:
198
-
199
- - **single**: Short push (approx. 1/2 seconds)
200
- - **double**: 2x sequential short pushes (within 2 seconds)
201
- - **long**: Long push (approx. 2 seconds)
202
- - **touch**: Touch of the button's surface (only affective for the WiFi
203
- Button +)
204
-
205
- The button is set up to extend the life span of the battery as much as
206
- possible. This means that only within the first 3 minutes or when connected
207
- to an USB port/USB charger and the battery is not full, the button is able
208
- to receive configuration information or publish its details.
209
-
210
- ``mystrom`` helper tool
211
- -----------------------
212
-
213
- The command-line tool ``mystrom`` can help to set up the buttons and get the
214
- details from bulbs and plugs.
215
-
216
- .. code:: bash
217
-
218
- $ mystrom
219
- Usage: mystrom [OPTIONS] COMMAND [ARGS]...
220
-
221
- Simple command-line tool to get and set the values of a myStrom devices.
222
-
223
- This tool can set the targets of a myStrom button for the different
224
- available actions single, double, long and touch.
225
-
226
- Options:
227
- --version Show the version and exit.
228
- --help Show this message and exit.
229
-
230
- Commands:
231
- bulb Get and set details of a myStrom bulb.
232
- button Get and set details of a myStrom button.
233
- config Get and set the configuration of a myStrom...
234
-
235
- The examples shows how to get the details of a given bulb.
236
-
237
- .. code:: bash
238
-
239
- $ mystrom config read
240
- IP address of the myStrom device: IP_ADDRESS_BULB
241
- MAC address of the device: MAC_ADDRESS_BULB
242
- Read configuration from IP_ADDRESS_BULB
243
- {
244
- 'MAC_ADDRESS_BULB':{
245
- 'type':'rgblamp',
246
- 'battery':False,
247
- 'reachable':True,
248
- 'meshroot':False,
249
- 'on':True,
250
- 'color':'191;90;14',
251
- 'mode':'hsv',
252
- 'ramp':100,
253
- 'power':0.953,
254
- 'fw_version':'2.25'
255
- }
256
- }
257
-
258
- Example usage of the module
259
- ---------------------------
260
-
261
- Examples for the bulb can be found in the directory ``examples``.
262
-
263
- License
264
- -------
265
-
266
- ``python-mystrom`` is licensed under MIT, for more details check LICENSE.
267
-
268
- .. |License| image:: https://img.shields.io/badge/License-MIT-green.svg
269
- :target: https://pypi.python.org/pypi/python-mystrom
270
- :alt: License
271
-
272
- .. |PyPI| image:: https://img.shields.io/pypi/v/python-mystrom.svg
273
- :target: https://pypi.python.org/pypi/python-mystrom
274
- :alt: PyPI release
@@ -1,18 +0,0 @@
1
- """Example code for communicating with a myStrom bulb and HSV values."""
2
- import time
3
-
4
- from pymystrom import bulb
5
-
6
- bulb = bulb.MyStromBulb("192.168.0.51", "5CCF7FA0AFB0")
7
-
8
- bulb.set_color_hex("000000FF")
9
-
10
- # Get the details of the bulb
11
- print("Current color details:", bulb.get_color())
12
-
13
- # Set color as HSV (Hue, Saturation, Value)
14
- bulb.set_color_hsv(50, 100, 100)
15
- time.sleep(3)
16
-
17
- # Shutdown the bulb
18
- bulb.set_off()
@@ -1,72 +0,0 @@
1
- """Example code for communicating with a myStrom bulb."""
2
- import asyncio
3
- import logging
4
-
5
- from pymystrom.bulb import MyStromBulb
6
- from pymystrom.discovery import discover_devices
7
-
8
- IP_ADDRESS = "192.168.0.51"
9
- MAC_ADDRESS = "5CCF7FA0AFB0"
10
-
11
-
12
- async def main():
13
- """Sample code to work with a myStrom bulb."""
14
- # Discover myStrom bulbs devices
15
- devices = await discover_devices()
16
-
17
- print(f"Found {len(devices)} bulb(s)")
18
- for device in devices:
19
- print(f" IP address: {device.host}, MAC address: {device.mac}")
20
-
21
- async with MyStromBulb(IP_ADDRESS, MAC_ADDRESS) as bulb:
22
- print("Get the details from the bulb...")
23
- await bulb.get_state()
24
-
25
- print("Power consumption:", bulb.consumption)
26
- print("Firmware:", bulb.firmware)
27
- print("Current state:", "off" if bulb.state is False else "on")
28
-
29
- print("Bulb will be switched on with their previous setting")
30
- await bulb.set_on()
31
- # print("Waiting for a couple of seconds...")
32
- await asyncio.sleep(2)
33
- print("Bulb will be set to white")
34
- await bulb.set_white()
35
- # Wait a few seconds to get a reading of the power consumption
36
- print("Waiting for a couple of seconds...")
37
-
38
- await asyncio.sleep(2)
39
- # Set transition time to 2 s
40
- await bulb.set_transition_time(2000)
41
-
42
- # Set to blue as HEX
43
- await bulb.set_color_hex("000000FF")
44
- await asyncio.sleep(3)
45
-
46
- # Set color as HSV (Hue, Saturation, Value)
47
- await bulb.set_color_hsv(0, 0, 100)
48
- await asyncio.sleep(3)
49
-
50
- # Test a fast flashing sequence
51
- print("Flash it for 10 seconds...")
52
- await bulb.set_flashing(10, [100, 50, 30], [200, 0, 71])
53
- await bulb.set_off()
54
-
55
- # Show a sunrise within a minute
56
- print("Show a sunrise for 60 s")
57
- await bulb.set_sunrise(60)
58
-
59
- # Show a rainbow for 60 seconds
60
- print("Show a rainbow")
61
- await bulb.set_rainbow(60)
62
- # Reset transition time
63
- await bulb.set_transition_time(1000)
64
-
65
- # Shutdown the bulb
66
- await bulb.set_off()
67
-
68
-
69
- if __name__ == "__main__":
70
- logging.basicConfig(level=logging.DEBUG)
71
- loop = asyncio.get_event_loop()
72
- loop.run_until_complete(main())
@@ -1,13 +0,0 @@
1
- import asyncio
2
-
3
- from pymystrom import discovery
4
-
5
- async def main():
6
- """Sample code to work with discovery."""
7
- # Discover all bulbs in the network via broadcast datagram (UDP)
8
- bulbs = await discovery.discover_devices()
9
- print(f"Number of detected bulbs: {len(bulbs)}")
10
-
11
- if __name__ == "__main__":
12
- loop = asyncio.get_event_loop()
13
- loop.run_until_complete(main())
@@ -1,12 +0,0 @@
1
- """Example code for getting the data from a myStrom bulb."""
2
- from pymystrom import bulb
3
-
4
- bulb = bulb.MyStromBulb("192.168.0.51", "5CCF7FA0AFB0")
5
-
6
- # Get the details of the bulb
7
- print("Bulb state:", bulb.get_bulb_state())
8
- print("Current color:", bulb.get_color())
9
- print("Brightness:", bulb.get_brightness())
10
- print("Power consumption:", bulb.get_power())
11
- print("Transition time:", bulb.get_transition_time())
12
- print("Firmware version:", bulb.get_firmware())
@@ -1,42 +0,0 @@
1
- """Example code for communicating with a myStrom PIR unit."""
2
- import asyncio
3
-
4
- from pymystrom.pir import MyStromPir
5
-
6
- IP_ADDRESS = "192.168.1.225"
7
-
8
-
9
- async def main():
10
- """Sample code to work with a myStrom PIR."""
11
- async with MyStromPir(IP_ADDRESS) as pir:
12
- # Get the PIR settings
13
- await pir.get_settings()
14
- print("Settings:", pir.settings)
15
-
16
- # Get the PIR settings
17
- await pir.get_pir()
18
- print("PIR settings:", pir.pir)
19
-
20
- # Collect the sensors
21
- await pir.get_sensors_state()
22
- print("Sensors:", pir.sensors)
23
-
24
- # Get the temperature data
25
- await pir.get_temperatures()
26
- print("Temperatures:", pir.temperature_raw)
27
- print("Temperature measured:", pir.temperature_measured)
28
-
29
- # Details of the light sensor
30
- await pir.get_light()
31
- print("Brightness:", pir.intensity)
32
- print("Day?:", pir.day)
33
- print("Raw light data:", pir.light_raw)
34
-
35
- # Get the action settings
36
- await pir.get_actions()
37
- print("Actions:", pir.actions)
38
-
39
-
40
- if __name__ == "__main__":
41
- loop = asyncio.get_event_loop()
42
- loop.run_until_complete(main())
@@ -1,36 +0,0 @@
1
- """Example code for communicating with a myStrom plug/switch."""
2
- import asyncio
3
-
4
- from pymystrom.switch import MyStromSwitch
5
-
6
- IP_ADDRESS = "192.168.0.40"
7
-
8
-
9
- async def main():
10
- """Sample code to work with a myStrom switch."""
11
- async with MyStromSwitch(IP_ADDRESS) as switch:
12
- # Collect the data of the current state
13
- await switch.get_state()
14
-
15
- print("Power consumption:", switch.consumption)
16
- print("Energy consumed:", switch.consumedWs)
17
- print("Relay state:", switch.relay)
18
- print("Temperature:", switch.temperature)
19
- print("Firmware:", switch.firmware)
20
- print("MAC address:", switch.mac)
21
-
22
- print("Turn on the switch")
23
- if not switch.relay:
24
- await switch.turn_on()
25
-
26
- # print("Toggle the switch")
27
- # await switch.toggle()
28
-
29
- # Switch relay off if it was off
30
- if switch.relay:
31
- await switch.turn_off()
32
-
33
-
34
- if __name__ == "__main__":
35
- loop = asyncio.get_event_loop()
36
- loop.run_until_complete(main())
@@ -1,24 +0,0 @@
1
- LICENSE
2
- MANIFEST.in
3
- README.rst
4
- setup.py
5
- examples/example-bulb-hsv.py
6
- examples/example-bulb.py
7
- examples/example-discovery.py
8
- examples/example-get-data-bulb.py
9
- examples/example-pir.py
10
- examples/example-switch.py
11
- pymystrom/__init__.py
12
- pymystrom/bulb.py
13
- pymystrom/cli.py
14
- pymystrom/discovery.py
15
- pymystrom/exceptions.py
16
- pymystrom/pir.py
17
- pymystrom/switch.py
18
- python_mystrom.egg-info/PKG-INFO
19
- python_mystrom.egg-info/SOURCES.txt
20
- python_mystrom.egg-info/dependency_links.txt
21
- python_mystrom.egg-info/entry_points.txt
22
- python_mystrom.egg-info/requires.txt
23
- python_mystrom.egg-info/top_level.txt
24
- python_mystrom.egg-info/zip-safe
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- mystrom = pymystrom.cli:main
@@ -1,4 +0,0 @@
1
- requests
2
- click
3
- aiohttp
4
- setuptools
@@ -1 +0,0 @@
1
- pymystrom
@@ -1,4 +0,0 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
@@ -1,48 +0,0 @@
1
- """Set up the Python API for myStrom devices."""
2
- import os
3
-
4
- import sys
5
-
6
- from setuptools import setup, find_packages
7
-
8
- here = os.path.abspath(os.path.dirname(__file__))
9
-
10
- with open(os.path.join(here, "README.rst"), encoding="utf-8") as readme:
11
- long_description = readme.read()
12
-
13
- setup(
14
- name="python-mystrom",
15
- version="2.2.0",
16
- description="Asynchronous Python API client for interacting with myStrom devices",
17
- long_description=long_description,
18
- url="https://github.com/home-assistant-ecosystem/python-mystrom",
19
- author="Fabian Affolter",
20
- author_email="fabian@affolter-engineering.ch",
21
- license="MIT",
22
- install_requires=[
23
- "requests",
24
- "click",
25
- "aiohttp",
26
- "setuptools",
27
- ],
28
- packages=find_packages(),
29
- python_requires=">=3.9",
30
- zip_safe=True,
31
- include_package_data=True,
32
- entry_points="""
33
- [console_scripts]
34
- mystrom=pymystrom.cli:main
35
- """,
36
- classifiers=[
37
- "Development Status :: 3 - Alpha",
38
- "Environment :: Console",
39
- "Intended Audience :: Developers",
40
- "License :: OSI Approved :: MIT License",
41
- "Operating System :: MacOS :: MacOS X",
42
- "Operating System :: Microsoft :: Windows",
43
- "Operating System :: POSIX",
44
- "Programming Language :: Python :: 3.9",
45
- "Programming Language :: Python :: 3.10",
46
- "Topic :: Utilities",
47
- ],
48
- )