diff --git a/aioshelly/block_device/device.py b/aioshelly/block_device/device.py index 41fdcdf9..4fca5dbc 100644 --- a/aioshelly/block_device/device.py +++ b/aioshelly/block_device/device.py @@ -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, @@ -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 diff --git a/aioshelly/exceptions.py b/aioshelly/exceptions.py index b14f476f..36f6b12d 100644 --- a/aioshelly/exceptions.py +++ b/aioshelly/exceptions.py @@ -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.""" diff --git a/tools/example.py b/tools/example.py index 49030bb0..ae3fb800 100644 --- a/tools/example.py +++ b/tools/example.py @@ -26,6 +26,7 @@ from aioshelly.common import ConnectionOptions from aioshelly.const import WS_API_URL from aioshelly.exceptions import ( + CustomPortNotSupported, DeviceConnectionError, FirmwareUnsupported, InvalidAuthError, @@ -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)