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

How to write fields with mate3 cli? #38

Open
rrooggiieerr opened this issue Feb 24, 2022 · 2 comments
Open

How to write fields with mate3 cli? #38

rrooggiieerr opened this issue Feb 24, 2022 · 2 comments

Comments

@rrooggiieerr
Copy link

Hi! I now got the mate3 cli working after some debugging and fixing issues in the code (see my pull request with the modifications I did)

It's not yet entirely clear how can I should write values to the mate3 using the mate3 cli

I'm trying to switch on the AUX port on our secondary inverter

This is what I've got:
mate3 write --set single_phase_radian_inverters[2].config.aux_control=<what goes here?> --host <ip>

The code does an eval() on the provided value, but it's not entirely clear what should I use as the value?

When I import from mate3.sunspec.models import RadianInverterConfigurationModel in mate3/main.py and use RadianInverterConfigurationModel.aux_control.options.On I can switch on the AUX port. Are there just some imports missing and is the way it was intended to work, or should I do something else?

@kodonnell
Copy link
Collaborator

kodonnell commented Feb 28, 2022

Thanks for looking into this and the PR @rrooggiieerr - I'll try to look in the next few days. If I remember correctly, what you want is something like this

--set single_phase_radian_inverters[2].config.aux_control="RadianInverterConfigurationModel.aux_control.options['On']"

or (possibly equivalently)

--set single_phase_radian_inverters[2].config.aux_control="client.devices.single_phase_radian_inverters[2].config.aux_control.field.options['On']"

Just a note though - as per the readme, it's encouraged to use the Python API for writing if you can, as this one isn't great given the eval etc. Edit - just realised you've already tried the API = )

Are there just some imports missing and is the way it was intended to work, or should I do something else?

I'm not sure - what errors are you getting? If the first one fails due to RadianInverterConfigurationModel not being found (which, looking at it, seems likely) then that might be a case for a star import in main.py.

Generally, if you've got ideas to make it better, let me know (or submit a PR!) - the main problem is there's just such a large number of different fields and devices, and when coupled with enums, values just get pretty long.

@rrooggiieerr
Copy link
Author

@kodonnell I'm aware of the eval in the CLI, how about extending FieldValue with the possible options for that field. These options can then be referred to when setting the field value.

like

field = get_field(client.devices, attr_idx_pattern.findall(path))
value = field.options[value]
field.write(value)

The argument to the CLI to set a field would then become

--set single_phase_radian_inverters[2].config.aux_control=On

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants