question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return units within the JSON response

See original GitHub issue

Hello, is there a way to add a new output perhaps that returns the unit with the value in json format?

Specifically, I would like data[key][1] to be returned within the JSON.

Here’s the snipped I’m talking about but I’m not sure what would be the best solution regarding specifying a certain flag or a new output type in order to not cause any regressions.

https://github.com/jblance/mpp-solar/blob/6ba5268673280c6c86c6053b01d4d3d86cb2a8df/mppsolar/outputs/__init__.py#L84-L99

In other words, I’m looking for an output similar to this:

{ "ac_output_voltage": { "value": 220, "unit": "V" }, ... }

Instead of this:

{ "ac_output_voltage": 220, ... }

Issue Analytics

  • State:open
  • Created 9 months ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jblancecommented, Dec 23, 2022

I suggest something similar

    // Register QPIGS Sensors
    register_sensor(client, cfg, "qpigs", "grid_voltage", "Grid Voltage", Some("V".to_string()), "power-plug").await?;
    register_sensor(client, cfg, "qpigs", "grid_frequency", "Grid Frequency", Some("Hz".to_string()), "current-ac").await?;
    register_sensor(client, cfg, "qpigs", "ac_out_voltage", "Out Voltage", Some("V".to_string()), "power-plug").await?;
    register_sensor(client, cfg, "qpigs", "ac_out_frequency", "Out Frequency", Some("Hz".to_string()), "current-ac").await?;
    register_sensor(client, cfg, "qpigs", "ac_out_apparent_power", "Out apparent power", Some("W".to_string()), "power-plug").await?;
    register_sensor(client, cfg, "qpigs", "ac_out_active_power", "Out active power", Some("W".to_string()), "power-plug").await?;
    register_sensor(client, cfg, "qpigs", "out_load_percent", "Out load percent", Some("%".to_string()), "brightness-percent").await?;
    register_sensor(client, cfg, "qpigs", "bus_voltage", "Bus Voltage", Some("V".to_string()), "details").await?;
    register_sensor(client, cfg, "qpigs", "battery_voltage", "Battery Voltage", Some("V".to_string()), "battery-outline").await?;
    register_sensor(client, cfg, "qpigs", "battery_charge_current", "Battery charge current", Some("A".to_string()), "current-dc").await?;
    register_sensor(client, cfg, "qpigs", "battery_capacity", "Battery capacity", Some("%".to_string()), "battery-outline").await?;
    register_sensor(client, cfg, "qpigs", "inverter_heat_sink_temp", "Heat sink temperature", Some("°C".to_string()), "details").await?;
    register_sensor(client, cfg, "qpigs", "pv_input_current", "PV Input Current", Some("A".to_string()), "solar-power").await?;
    register_sensor(client, cfg, "qpigs", "pv_input_voltage", "PV Input Voltage", Some("V".to_string()), "solar-power").await?;
    register_sensor(client, cfg, "qpigs", "battery_scc_voltage", "Battery SCC Voltage", Some("V".to_string()), "current-dc").await?;
    register_sensor(client, cfg, "qpigs", "battery_discharge_current", "Battery discharge current", Some("A".to_string()), "battery-negative").await?;
    register_sensor(client, cfg, "qpigs", "device_status.charge_status", "Device charge status", None, "power-plug").await?;
    register_sensor(client, cfg, "qpigs", "device_status.active_load", "Active load", None, "power").await?;

#269 (comment)

this one is a bit harder as i need to refactor to core code and expand the command definitions - working on it though

0reactions
ziadakikicommented, Dec 24, 2022

Thanks for that! I guess an output called json_mqtt_units or something similar should be added as well. Same goes for UDP (for completeness).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to unit test an Action method which returns JsonResult?
JsonResult returns an anonymous object and these are, by default, internal , so they need to be made visible to the tests project....
Read more >
Spring Web MVC – Return JSON in Response Body
In this tutorial, you will learn how to use the @ResponseBody annotation to return JSON in the HTTP response body.
Read more >
Unit Testing — Parsing a JSON response - Medium
Remind that the server can return different responses e.g. a 404 status. We need to parse our JSON, that means to grab the...
Read more >
Response.json() - Web APIs - MDN Web Docs
The json() method of the Response interface takes a Response stream and reads it to completion. It returns a promise which resolves with...
Read more >
Spring Web MVC | 12 | Return JSON in Response Body
In this video lesson, you will learn how to return JSON in HTTP Response Body of your Spring MVC Web application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found