mirror of
https://github.com/suaveolent/hoymiles-wifi.git
synced 2024-09-20 03:10:11 +00:00
Merge e211658185
into 255a9109d8
This commit is contained in:
commit
6444872feb
@ -108,35 +108,43 @@ async def async_app_get_hist_power(
|
|||||||
|
|
||||||
|
|
||||||
async def async_set_power_limit(
|
async def async_set_power_limit(
|
||||||
dtu: DTU,
|
dtu: DTU, power_limit=-1
|
||||||
) -> CommandPB_pb2.CommandResDTO | None:
|
) -> CommandPB_pb2.CommandResDTO | None:
|
||||||
"""Set the power limit of the inverter asynchronously."""
|
"""Set the power limit of the inverter asynchronously."""
|
||||||
|
|
||||||
print( # noqa: T201
|
if power_limit == -1:
|
||||||
RED
|
print( # noqa: T201
|
||||||
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
|
RED
|
||||||
+ "!!! Danger zone! This will change the power limit of the dtu. !!!\n"
|
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
|
||||||
+ "!!! Please be careful and make sure you know what you are doing. !!!\n"
|
+ "!!! Danger zone! This will change the power limit of the dtu. !!!\n"
|
||||||
+ "!!! Only proceed if you know what you are doing. !!!\n"
|
+ "!!! Please be careful and make sure you know what you are doing. !!!\n"
|
||||||
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
|
+ "!!! Only proceed if you know what you are doing. !!!\n"
|
||||||
+ END,
|
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"
|
||||||
)
|
+ END,
|
||||||
|
)
|
||||||
|
|
||||||
cont = input("Do you want to continue? (y/n): ")
|
cont = input("Do you want to continue? (y/n): ")
|
||||||
if cont != "y":
|
if cont != "y":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
power_limit = int(input("Enter the new power limit (0-100): "))
|
power_limit = int(input("Enter the new power limit (0-100): "))
|
||||||
|
forced_argument = False # we've retrieved the power limit in interactive mode
|
||||||
|
|
||||||
|
else:
|
||||||
|
forced_argument = True # we've retrieved the power limit via argument
|
||||||
|
|
||||||
if power_limit < 0 or power_limit > MAX_POWER_LIMIT:
|
if power_limit < 0 or power_limit > MAX_POWER_LIMIT:
|
||||||
print("Error. Invalid power limit!") # noqa: T201
|
print("Error. Invalid power limit!") # noqa: T201
|
||||||
return None
|
return None
|
||||||
|
|
||||||
print(f"Setting power limit to {power_limit}%") # noqa: T201
|
print(f"Setting power limit to {power_limit}%") # noqa: T201
|
||||||
cont = input("Are you sure? (y/n): ")
|
|
||||||
|
if not forced_argument:
|
||||||
|
# the limit has been set in interactive mode, so we ask for confirmation
|
||||||
|
cont = input("Are you sure? (y/n): ")
|
||||||
|
|
||||||
if cont != "y":
|
if cont != "y":
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return await dtu.async_set_power_limit(power_limit)
|
return await dtu.async_set_power_limit(power_limit)
|
||||||
|
|
||||||
@ -351,6 +359,15 @@ async def main() -> None:
|
|||||||
],
|
],
|
||||||
help="Command to execute",
|
help="Command to execute",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--force",
|
||||||
|
type=int,
|
||||||
|
nargs='?',
|
||||||
|
const=-1,
|
||||||
|
default=-1,
|
||||||
|
help="Do not confirm certain operations and take arguments directly from commandline",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
dtu = DTU(args.host, args.local_addr)
|
dtu = DTU(args.host, args.local_addr)
|
||||||
@ -378,7 +395,10 @@ async def main() -> None:
|
|||||||
}
|
}
|
||||||
|
|
||||||
command_func = switch.get(args.command, print_invalid_command)
|
command_func = switch.get(args.command, print_invalid_command)
|
||||||
response = await command_func(dtu)
|
if args.command == 'set-power-limit':
|
||||||
|
response = await command_func(dtu, args.force)
|
||||||
|
else:
|
||||||
|
response = await command_func(dtu)
|
||||||
|
|
||||||
if response:
|
if response:
|
||||||
if args.as_json:
|
if args.as_json:
|
||||||
|
Loading…
Reference in New Issue
Block a user