diff --git a/docs/shinephone.md b/docs/shinephone.md index 7de3264..cdff7da 100644 --- a/docs/shinephone.md +++ b/docs/shinephone.md @@ -63,6 +63,7 @@ Any methods that may be useful. | `api.update_mix_inverter_setting(serial_number, setting_type, parameters)` | serial_number: String, setting_type: String, parameters: Dict/Array | Apply the provided parameters for the specified setting on the specified Mix inverter. see: [details](./shinephone/inverter_settings.md) | | `api.update_ac_inverter_setting(serial_number, setting_type, parameters)` | serial_number: String, setting_type: String, parameters: Dict/Array | Apply the provided parameters for the specified setting on the specified AC-coupled inverter. see: [details](./shinephone/inverter_settings.md) | | `api.update_noah_settings(serial_number, setting_type, parameters)` | serial_number: String, setting_type: String, parameters: Dict/Array | Apply the provided parameters for the specified setting on the specified Noah device. see: [details](./shinephone/noah_settings.md) | +| `api.update_classic_inverter_setting(default_parameters, parameters)` | default_parameters: Dict, parameters: Dict/Array | Applies settings for specified system based on serial number. This function is only going to work for classic inverters. | ### Variables diff --git a/docs/shinephone/inverter_settings.md b/docs/shinephone/inverter_settings.md index 1476c0b..854754c 100644 --- a/docs/shinephone/inverter_settings.md +++ b/docs/shinephone/inverter_settings.md @@ -78,6 +78,13 @@ Known working settings & parameters are as follows (all parameter values are str * start_time: timedate object with start time of segment with format HH:MM * end_time: timedate object with end time of segment with format HH:MM * enabled: time segment enabled, boolean: True (Enabled), False (Disabled) +* **Classic inverter settings** + * function: `api.update_classic_inverter_setting` + * description: Applies settings for specified system based on serial number. This function is only going to work for classic inverters. + * params: + * `param1`: First parameter (specific to the setting type) + * `param2`: Second parameter (specific to the setting type) + * Additional parameters can be passed as needed. The four functions `update_tlx_inverter_setting`, `update_mix_inverter_setting`, `update_ac_inverter_setting`, and `update_inverter_setting` take either a dictionary or an array. If an array is passed it will automatically generate the `paramN` key based on array index since all params for settings seem to used the same numbering scheme. diff --git a/examples/settings_example_classic.py b/examples/settings_example_classic.py new file mode 100644 index 0000000..ef79c54 --- /dev/null +++ b/examples/settings_example_classic.py @@ -0,0 +1,49 @@ +import growattServer +import getpass +import pprint + +""" +This script demonstrates how to interface with the configuration settings of a plant and its classic inverters. +It uses the `update_classic_inverter_setting` function to apply settings to a classic inverter. +""" +pp = pprint.PrettyPrinter(indent=4) + +# Prompt user for username +username = input("Enter username:") + +# Prompt user to input password +user_pass = getpass.getpass("Enter password:") + +api = growattServer.GrowattApi(True, username) +login_response = api.login(username, user_pass) + +plant_list = api.plant_list(login_response['user']['id']) + +# Simple logic to just get the first inverter from the first plant +# Expand this using a for-loop to perform for more systems +plant = plant_list['data'][0] # This is an array - we just take the first - would need a for-loop for more systems +plant_id = plant['plantId'] +plant_name = plant['plantName'] +plant_info = api.plant_info(plant_id) + +devices = api.device_list(plant_id) +device = devices[0] # This is an array - we just take the first - would need a for-loop for more systems +device_sn = device['deviceSn'] +device_type = device['deviceType'] + +# Turn inverter on +print("Turning on inverter: %s" % (device_sn)) + +# Set up the default parameters +default_parameters = { + "action": "inverterSet", + "serialNum": device_sn, +} + +parameters = { + "paramId": "pv_on_off", + "command_1": "0001", # 0001 to turn on, 0000 to turn off + "command_2": "", # Empty string for command_2 as not used +} +response = api.update_classic_inverter_setting(default_parameters, parameters) +print(response) \ No newline at end of file diff --git a/growattServer/base_api.py b/growattServer/base_api.py index 0f74fff..41e009d 100644 --- a/growattServer/base_api.py +++ b/growattServer/base_api.py @@ -1176,3 +1176,31 @@ def update_noah_settings(self, serial_number, setting_type, parameters): data=settings_parameters) return response.json() + + def update_classic_inverter_setting(self, default_parameters, parameters): + """ + Applies settings for specified system based on serial number + See README for known working settings + + Arguments: + default_params -- Default set of parameters for the setting call (dict) + parameters -- Parameters to be sent to the system (dict or list of str) + (array which will be converted to a dictionary) + + Returns: + JSON response from the server whether the configuration was successful + """ + settings_parameters = parameters + + # If we've been passed an array then convert it into a dictionary + if isinstance(parameters, list): + settings_parameters = {} + for index, param in enumerate(parameters, start=1): + settings_parameters['param' + str(index)] = param + + settings_parameters = {**default_parameters, **settings_parameters} + + response = self.session.post(self.get_url('tcpSet.do'), + params=settings_parameters) + + return response.json() \ No newline at end of file