Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Gen3 devices #457

Merged
merged 8 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aioshelly/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
MODEL_PRO_EM3 = "SPEM-003CEBEU"
MODEL_PRO_EM3_400 = "SPEM-003CEBEU400"
MODEL_WALL_DISPLAY = "SAWD-0A1XX10EU1"
# Gen3 RPC based models
MODEL_PLUS_1_MINI_G3 = "S3SW-001X8EU"

MODEL_NAMES = {
# Gen1 CoAP based models
Expand Down Expand Up @@ -175,7 +177,6 @@
MODEL_PRO_2_V3: "Shelly Pro 2",
MODEL_PRO_2PM: "Shelly Pro 2PM",
MODEL_PRO_2PM_V2: "Shelly Pro 2PM",
MODEL_PRO_2PM_V2: "Shelly Pro 2PM",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate removed

MODEL_PRO_3: "Shelly Pro 3",
MODEL_PRO_4PM: "Shelly Pro 4PM",
MODEL_PRO_4PM_V2: "Shelly Pro 4PM",
Expand All @@ -184,6 +185,8 @@
MODEL_PRO_EM3: "Shelly Pro 3EM",
MODEL_PRO_EM3_400: "Shelly Pro 3EM-400",
MODEL_WALL_DISPLAY: "Shelly Wall Display",
# Gen3 RPC based models
MODEL_PLUS_1_MINI_G3: "Shelly Plus 1 Mini",
}

# Timeout used for Device IO
Expand Down
7 changes: 5 additions & 2 deletions aioshelly/rpc_device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,11 @@ def shelly(self) -> dict[str, Any]:

@property
def gen(self) -> int:
"""Device generation: GEN2 - RPC."""
return 2
"""Device generation: GEN2/3 - RPC."""
if self._shelly is None:
raise NotInitialized

return cast(int, self._shelly["gen"])

@property
def firmware_version(self) -> str:
Expand Down
19 changes: 14 additions & 5 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def create_device(
init: bool,
gen: int | None,
) -> Any:
"""Create a Gen1/Gen2 device."""
"""Create a Gen1/Gen2/Gen3 device."""
if gen is None:
if info := await aioshelly.common.get_info(aiohttp_session, options.ip_address):
gen = info.get("gen", 1)
Expand All @@ -49,7 +49,7 @@ async def create_device(
if gen == 1:
return await BlockDevice.create(aiohttp_session, coap_context, options, init)

if gen == 2:
if gen in (2, 3):
bieniu marked this conversation as resolved.
Show resolved Hide resolved
return await RpcDevice.create(aiohttp_session, ws_context, options, init)

raise ShellyError("Unknown Gen")
Expand Down Expand Up @@ -192,7 +192,7 @@ def print_block_device(device: BlockDevice) -> None:


def print_rpc_device(device: RpcDevice) -> None:
"""Print RPC (GEN2) device data."""
"""Print RPC (GEN2/3) device data."""
print(f"Status: {device.status}")
print(f"Event: {device.event}")
print(f"Connected: {device.connected}")
Expand Down Expand Up @@ -243,6 +243,9 @@ def get_arguments() -> tuple[argparse.ArgumentParser, argparse.Namespace]:
parser.add_argument(
"--gen2", "-g2", action="store_true", help="Force Gen 2 (RPC) device"
)
parser.add_argument(
"--gen3", "-g3", action="store_true", help="Force Gen 3 (RPC) device"
)
parser.add_argument(
"--debug", "-deb", action="store_true", help="Enable debug level for logging"
)
Expand All @@ -254,7 +257,7 @@ def get_arguments() -> tuple[argparse.ArgumentParser, argparse.Namespace]:
"--update_ws",
"-uw",
type=str,
help="Update outbound WebSocket (Gen2) and exit",
help="Update outbound WebSocket (Gen2/3) and exit",
)

arguments = parser.parse_args()
Expand All @@ -265,7 +268,7 @@ def get_arguments() -> tuple[argparse.ArgumentParser, argparse.Namespace]:
async def update_outbound_ws(
options: ConnectionOptions, init: bool, ws_url: str
) -> None:
"""Update outbound WebSocket URL (Gen2)."""
"""Update outbound WebSocket URL (Gen2/3)."""
async with aiohttp.ClientSession() as aiohttp_session:
device: RpcDevice = await create_device(aiohttp_session, options, init, 2)
print(f"Updating outbound weboskcet URL to {ws_url}")
Expand All @@ -281,12 +284,18 @@ async def main() -> None:

if args.gen1 and args.gen2:
parser.error("--gen1 and --gen2 can't be used together")
elif args.gen1 and args.gen3:
parser.error("--gen1 and --gen3 can't be used together")
elif args.gen2 and args.gen3:
parser.error("--gen2 and --gen3 can't be used together")

gen = None
if args.gen1:
gen = 1
elif args.gen2:
gen = 2
elif args.gen3:
gen = 3

if args.debug:
logging.basicConfig(level="DEBUG", force=True)
Expand Down