Skip to content

feat(calin-meter-v2): add Calin Meter API V2 (AMR) plugin - #1781

Open
beesaferoot wants to merge 9 commits into
mainfrom
feat/calin-meter-v2
Open

beesaferoot wants to merge 9 commits into
mainfrom
feat/calin-meter-v2

Conversation

@beesaferoot

@beesaferoot beesaferoot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Brief summary of the change made

closes: #1726
closes: #1776

Newer Calin installations run Calin's API V2 (AMR), each on its own host and port.
This PR adds a CalinMeterV2 manufacturer plugin for them.
It covers both STS keypad meters and smart meters on API V2.

  • Logs in for a JWT, keeps the access token and logs in again once it expires.
    An optional company name is sent at login when set.
  • Vends tokens in one of two ways, chosen in the Vend by setting:
    • Energy (default): MPM converts the payment to kWh with its tariff and asks Calin for that energy.
    • Amount paid: MPM sends the paid amount (isVendByTotalPaid: true) and Calin applies the tariff stored on its side.
      In both modes the units Calin reports (totalUnit) are recorded.
  • Sends an optional authorization password with vend requests, for systems that ask for one.
  • Issues clear credit tokens and checks whether a meter is registered on Calin, for the ad-hoc device control.
  • Saves credentials only after Calin accepts a login with them.
  • Corrects common address mistakes: a trailing /api is dropped, and a web dashboard address is replaced by the API address the dashboard names.

The plugin was started by @beesaferoot; the vend mode setting and the authorization password were added by me.

Are there any other side effects of this change that we should be aware of?

No.
The legacy CalinMeter and CalinSmartMeter plugins are not changed.

This branch uses plugin id 34, the same as #1779; #1780 and #1782 use 35 and 36.
Whichever is merged later needs a new id.

Describe how you tested your changes?

  • Unit tests for the API client, the credential service and the token issuer, and a feature test for the device control.
  • composer quality:check passes; ESLint and Prettier pass.
  • Against two live Calin API V2 installations, from a local instance:
    • Keypad installation, vend by amount paid: without the authorization password Calin answered Incorrect authorization password (code 99).
      With it, a payment of 1,000 at a tariff of 1,830 returned a token and totalUnit 0.5.
    • Smart meter installation, login with company name, vend by energy: 1 kWh returned a token and totalUnit 1.
      The meter lookup (/api/meter/read) returned the meter as registered.

AI disclosure

I used Claude Code for the vend mode setting, the authorization password and their tests and documentation.

Pull Request checklist

  • Meaningful Pull Request title and description
  • Changes tested as described above
  • Added appropriate documentation for the change.
  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

Newer Calin installations run Calin's API V2 (AMR), each on its own host
and port. Adds a CalinMeterV2 manufacturer plugin next to the existing
Calin plugins instead of rewriting CalinSmartMeter in place, so tenants
on the older APIs keep vending.

- Logs in for a JWT, keeps the access token and logs in again once it
  expires.
- Vends kWh tokens and records the units Calin reports it issued.
- Issues clear credit tokens and checks whether a meter is registered
  on Calin, for the ad-hoc device control.
- Saves credentials only after Calin accepts a login with them. An
  optional company name is sent at login when set.
- Corrects common address mistakes: a trailing /api is dropped, and a
  web dashboard address is replaced by the API address the dashboard
  names.
- Credentials page with the same status card as Spark SHS, sidebar
  entry, locale labels and docs.

Refs #1726
@beesaferoot beesaferoot changed the title Draft: feat(calin-meter-v2): add Calin Meter API V2 (AMR) plugin Draft: add Calin Meter API V2 (AMR) plugin Nov 26, 2026
@beesaferoot beesaferoot changed the title Draft: add Calin Meter API V2 (AMR) plugin draft: add Calin Meter API V2 (AMR) plugin Nov 26, 2026
@beesaferoot beesaferoot changed the title draft: add Calin Meter API V2 (AMR) plugin draft: feat(calin-meter-v2): add Calin Meter API V2 (AMR) plugin Nov 26, 2026
…password

- add a "Vend by" setting: energy (default) or amount paid, where Calin
  applies the tariff stored on its side
- send an optional authorization password with vend requests, for
  systems that ask for one
- document both in the plugin's page

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@93Kamuran

Copy link
Copy Markdown
Contributor

I pushed one commit on top of your branch:

  • Vend by setting: energy (default, as you had it) or amount paid (isVendByTotalPaid: true).
  • Optional authorization password, sent with the vend request when set.
  • Both documented in the plugin page; three new unit tests.

Tested against our two live installations, from a local instance:

  • Keypad installation, vend by amount paid: without the authorization password Calin answered Incorrect authorization password (code 99). With it, a payment of 1,000 at a tariff of 1,830 returned a token and totalUnit 0.5.
  • Smart meter installation, login with company name, vend by energy: 1 kWh returned a token and totalUnit 1. The meter lookup (/api/meter/read) returned the meter as registered.

One thing to sort out: this branch uses plugin id 34, the same as #1779. #1780 and #1782 use 35 and 36. Whichever is merged later needs a new id.

I used Claude Code for the changes.

@93Kamuran 93Kamuran changed the title draft: feat(calin-meter-v2): add Calin Meter API V2 (AMR) plugin feat(calin-meter-v2): add Calin Meter API V2 (AMR) plugin Nov 26, 2026
@93Kamuran
93Kamuran removed their request for review November 26, 2026 12:24
@93Kamuran

Copy link
Copy Markdown
Contributor

I removed myself as reviewer, since part of this PR is my own code. @dmohns, it is ready for your review: CI is green and it was tested against our two live installations (see the comment above).

“93Kamuran” and others added 7 commits November 27, 2026 12:48
Register the plugin by slug (calin_meter_v2) as introduced in #1777.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
# Conflicts:
#	src/backend/bootstrap/providers.php
# Conflicts:
#	src/backend/tests/Feature/MpmPluginCatalogTest.php
# Conflicts:
#	src/backend/bootstrap/providers.php
#	src/backend/tests/Feature/MpmPluginCatalogTest.php
#	src/frontend/src/ExportedRoutes.js
@93Kamuran

Copy link
Copy Markdown
Contributor

Branch updated to current main. This plugin has been running in production since 3 December and is vending tokens for live customers. @dmohns, could you take a look when you have time?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants