Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions bin/get_info.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ async def main():
"_status": None,
"_switch_status": None,
"_switch_usage": None,
"get_export_settings": None,
"get_home_gateway_list": None,
"get_accessories": None,
# "get_mode": None, # KeyError: 21669
"get_smart_switch_state": None,
"get_smart_circuits": None,
"get_smart_circuits_enhanced": None,
"get_stats": None,
}

Expand Down
Empty file modified bin/login.py
100644 → 100755
Empty file.
85 changes: 85 additions & 0 deletions bin/set_circuit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3
"""Get information about the FranklinHW installation."""

import argparse
import asyncio
import logging
import sys

from franklinwh import Client, TokenFetcher
import jsonpickle


def truthy(value: str) -> bool:
"""Convert a string to a boolean."""
sure = ("yes", "true", "t", "y", "1", "on")
nope = ("no", "false", "f", "n", "0", "off")
if value.lower() in sure:
return True
if value.lower() in nope:
return False
raise argparse.ArgumentTypeError(
"Boolean must be one of " + ", ".join(sure + nope) + "."
)


async def main():
"""Do all the work."""
parser = argparse.ArgumentParser(description="Get FranklinWH installation info.")
parser.add_argument(
"--debug",
action="store_true",
help="Enable debug logging.",
)
parser.add_argument(
"username",
type=str,
help="The username for the installation.",
)
parser.add_argument(
"password",
type=str,
help="The password for the installation.",
)
parser.add_argument(
"gateway",
type=str,
help="The gateway / serial number to query.",
)
parser.add_argument(
"--merged",
action=argparse.BooleanOptionalAction,
help="Merge Circuits 1 and 2.",
)
parser.add_argument(
"circuit",
type=int,
choices=range(1, 4),
help="The circuit number to query.",
)
parser.add_argument("on", type=truthy, help="Turn on or off.")

args = parser.parse_args()

if args.debug:
logging.basicConfig()
logging.getLogger("franklinwh").setLevel(logging.DEBUG)
logging.getLogger("httpx").setLevel(logging.DEBUG)

fetcher = TokenFetcher(args.username, args.password)
client = Client(fetcher, args.gateway)
if args.merged is not None:
await client.set_smart_circuits_merged(args.merged)
await client.set_circuit(args.circuit, args.on)

print( # noqa: T201
jsonpickle.dumps(
await client.get_smart_circuits_enhanced(), indent=2, unpicklable=False
)
)

sys.exit(0)


if __name__ == "__main__":
asyncio.run(main())
10 changes: 8 additions & 2 deletions franklinwh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,34 @@
from .caching_thread import CachingThread
from .client import (
AccessoryType,
Circuit,
Client,
EnhancedCircuit,
ExportMode,
ExportSettings,
GridStatus,
HttpClientFactory,
Mode,
SmartCircuits,
Stats,
SwitchState,
SwitchState, # deprecated
TokenFetcher,
)

__all__ = [
"DEFAULT_URL_BASE",
"AccessoryType",
"CachingThread",
"Circuit",
"Client",
"EnhancedCircuit",
"ExportMode",
"ExportSettings",
"GridStatus",
"HttpClientFactory",
"Mode",
"SmartCircuits",
"Stats",
"SwitchState",
"SwitchState", # deprecated
"TokenFetcher",
]
Loading