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 smb share feature for Chuangmi Camera #1482

Merged
merged 7 commits into from
Oct 10, 2022
Merged
Changes from 6 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
39 changes: 28 additions & 11 deletions miio/chuangmi_camera.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Xiaomi Chuangmi camera (chuangmi.camera.ipc009, ipc013, ipc019, 038a2) support."""

import enum
import ipaddress
import logging
import socket
from typing import Any, Dict
from urllib.parse import urlparse

import click

Expand Down Expand Up @@ -362,7 +365,7 @@ def get_nas_config(self):

@command(
click.argument("state", type=EnumType(NASState)),
click.argument("share"),
click.argument("share", type=str),
click.argument("sync-interval", type=EnumType(NASSyncInterval)),
click.argument("video-retention-time", type=EnumType(NASVideoRetentionTime)),
default_output=format_output("Setting NAS config to '{state.name}'"),
Expand All @@ -375,13 +378,27 @@ def set_nas_config(
video_retention_time: NASVideoRetentionTime = NASVideoRetentionTime.Week,
):
"""Set NAS configuration."""
if share is None:
share = {}
return self.send(
"nas_set_config",
{
"state": state,
"sync_interval": sync_interval,
"video_retention_time": video_retention_time,
},
)

params: dict[str, Any] = {
0x5e marked this conversation as resolved.
Show resolved Hide resolved
"state": state,
"sync_interval": sync_interval,
"video_retention_time": video_retention_time,
}

share = urlparse(share)
if share.scheme == "smb":
ip = socket.gethostbyname(share.hostname)
reversed_ip = ".".join(reversed(ip.split(".")))
addr = int(ipaddress.ip_address(reversed_ip))
rytilahti marked this conversation as resolved.
Show resolved Hide resolved

params["share"] = {
"type": 1,
"name": share.hostname,
"addr": addr,
"dir": share.path.lstrip("/"),
"group": "WORKGROUP",
"user": share.username,
"pass": share.password,
}

return self.send("nas_set_config", params)