python-swidget 1.4.2__tar.gz → 1.4.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-swidget
3
- Version: 1.4.2
3
+ Version: 1.4.4
4
4
  Summary: Python API for Swidget smart devices
5
5
  Home-page: https://github.com/swidget/python-swidget
6
6
  License: GPL-3.0-or-later
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-swidget"
3
- version = "1.4.2"
3
+ version = "1.4.4"
4
4
  description = "Python API for Swidget smart devices"
5
5
  license = "GPL-3.0-or-later"
6
6
  authors = ["Swidget"]
@@ -38,6 +38,7 @@ __version__ = version("python-swidget")
38
38
 
39
39
 
40
40
  __all__ = [
41
+ "detect_secure",
41
42
  "discover_devices",
42
43
  "discover_single",
43
44
  "provision_wifi",
@@ -43,19 +43,20 @@ async def detect_secure(host: str, timeout: float = DETECT_TIMEOUT_SEC) -> bool:
43
43
  timeout_obj = ClientTimeout(total=timeout)
44
44
  connector = TCPConnector(ssl=False, force_close=True)
45
45
  async with ClientSession(connector=connector, timeout=timeout_obj) as session:
46
+ # Try plaintext first: it's the cheap path (no TLS handshake on the
47
+ # MCU) and a 200 response unambiguously means plaintext mode.
46
48
  try:
47
- async with session.get(f"https://{host}/api/v1/summary") as resp:
48
- # 403 = "auth required" → secure firmware.
49
- # 200 without creds is unusual but still indicates HTTPS works.
50
- if resp.status in (200, 403):
51
- return True
49
+ async with session.get(f"http://{host}/api/v1/summary") as resp:
50
+ if resp.status == 200:
51
+ return False
52
52
  except (ClientError, asyncio.TimeoutError):
53
53
  pass
54
54
 
55
+ # Fall back to HTTPS. A 403 means the firmware is enforcing auth.
55
56
  try:
56
- async with session.get(f"http://{host}/api/v1/summary") as resp:
57
- if resp.status == 200:
58
- return False
57
+ async with session.get(f"https://{host}/api/v1/summary") as resp:
58
+ if resp.status == 403:
59
+ return True
59
60
  except (ClientError, asyncio.TimeoutError):
60
61
  pass
61
62
 
@@ -158,7 +159,7 @@ async def discover_single(
158
159
 
159
160
  def _get_device_class(device_type: DeviceType) -> Type[SwidgetDevice]:
160
161
  """Find SmartDevice subclass for device described by passed data."""
161
- if device_type == DeviceType.Outlet:
162
+ if device_type in (DeviceType.Outlet, DeviceType.Outlet20A):
162
163
  return SwidgetOutlet
163
164
  elif device_type == DeviceType.Switch:
164
165
  return SwidgetSwitch
@@ -26,11 +26,21 @@ class DeviceType(Enum):
26
26
 
27
27
  Dimmer = "dimmer"
28
28
  Outlet = "outlet"
29
+ Outlet20A = "outlet_20a"
29
30
  Switch = "switch"
30
31
  TimerSwitch = "pana_switch"
31
32
  RelaySwitch = "relay_switch"
32
33
  Unknown = -1
33
34
 
35
+ @classmethod
36
+ def _missing_(cls, value: object) -> "DeviceType":
37
+ """Map unknown values to ``Unknown`` instead of raising ValueError.
38
+
39
+ Lets the SDK report "Unknown device type: ..." with a usable
40
+ message rather than crashing on a future firmware variant.
41
+ """
42
+ return cls.Unknown
43
+
34
44
 
35
45
  class InsertType(Enum):
36
46
  """Insert type enum."""
@@ -46,6 +56,11 @@ class InsertType(Enum):
46
56
  WD = "WATER DETECTOR"
47
57
  Unknown = -1
48
58
 
59
+ @classmethod
60
+ def _missing_(cls, value: object) -> "InsertType":
61
+ """Map unknown values to ``Unknown`` instead of raising ValueError."""
62
+ return cls.Unknown
63
+
49
64
 
50
65
  class SelfDiagnosticErrorCodes(Enum):
51
66
  """Self-Diagnostic error codes."""
File without changes