Skip to content

Commit

Permalink
add exception CustomPortNotSupported
Browse files Browse the repository at this point in the history
  • Loading branch information
chemelli74 committed Feb 27, 2024
1 parent 2ab62dc commit 17126d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions aioshelly/block_device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ..common import ConnectionOptions, IpOrOptionsType, get_info, process_ip_or_options
from ..const import CONNECT_ERRORS, DEVICE_IO_TIMEOUT, HTTP_CALL_TIMEOUT, MODEL_RGBW2
from ..exceptions import (
CustomPortNotSupported,
DeviceConnectionError,
FirmwareUnsupported,
InvalidAuthError,
Expand Down Expand Up @@ -118,6 +119,10 @@ async def initialize(self, async_init: bool = False) -> None:
if self._initializing:
raise RuntimeError("Already initializing")

# GEN1 cannot be configured behind a range extender as CoAP port cannot be natted
if self.options.port != 80:
raise CustomPortNotSupported

self._initializing = True
self.initialized = False
ip = self.options.ip_address
Expand Down
4 changes: 4 additions & 0 deletions aioshelly/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class MacAddressMismatchError(ShellyError):
"""Raised if input MAC address does not match the device MAC address."""


class CustomPortNotSupported(ShellyError):
"""Raise if GEN1 devices are access with custom port."""


class RpcCallError(ShellyError):
"""Raised to indicate errors in RPC call."""

Expand Down
4 changes: 4 additions & 0 deletions tools/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from aioshelly.common import ConnectionOptions
from aioshelly.const import WS_API_URL
from aioshelly.exceptions import (
CustomPortNotSupported,
DeviceConnectionError,
FirmwareUnsupported,
InvalidAuthError,
Expand Down Expand Up @@ -56,6 +57,9 @@ async def test_single(options: ConnectionOptions, init: bool, gen: int | None) -
except WrongShellyGen:
print(f"Wrong Shelly generation {gen}, device gen: {2 if gen==1 else 1}")
return
except CustomPortNotSupported:
print(f"Custom port ({options.port}) not supported for Gen1")
return

print_device(device)

Expand Down

0 comments on commit 17126d4

Please sign in to comment.