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

Looking back and forward 24 hours in the Monta API #66

Merged
merged 2 commits into from
Oct 28, 2024

Conversation

tougher
Copy link
Contributor

@tougher tougher commented Oct 28, 2024

The code changes seem almost too simple. Should I put the 24 hours in variables like the new MatchingXToleranceMinutes?

Tested on my own data from the last 90 days, with only one failed calculation (edge-case, see more below).

The failed calculation is a super edge-case where the charge failed (for unknown reasons) at 67% and I continued it later in the app where it failed again!! after 8 minutes and I continued again. This yields 2 charges from the Monta API.
Just to make it clear, I don't think TeslaMateAgile should try to handle edge-cases like this, I just added it out of interest.

image
{
    "data": [
        {
            "id": 123,
            "chargePointId": 123,
            "createdAt": "2024-08-15T07:23:00Z",
            "updatedAt": "2024-08-15T11:59:08Z",
            "cablePluggedInAt": "2024-08-15T07:23:00Z",
            "startedAt": "2024-08-15T07:23:00Z",
            "stoppedAt": "2024-08-15T11:59:03Z",
            "fullyChargedAt": null,
            "failedAt": null,
            "timeoutAt": null,
            "state": "completed",
            "consumedKwh": 50.52,
            "kwhLimit": null,
            "startMeterKwh": 7955.649,
            "endMeterKwh": 8006.167,
            "cost": 12.17,
            "price": 105.01,
            "priceLimit": null,
            "averagePricePerKwh": 2.08,
            "averageCo2PerKwh": 137.83,
            "averageRenewablePerKwh": 81.73,
            "failureReason": null,
            "stopReason": "fully charged",
            "note": null,
            "currency": {
                "identifier": "dkk",
                "name": "Danish kroner",
                "decimals": 2
            },
            "soc": null,
            "socLimit": null
        },
        {
            "id": 123,
            "chargePointId": 123,
            "createdAt": "2024-08-15T07:22:22Z",
            "updatedAt": "2024-08-15T07:22:29Z",
            "cablePluggedInAt": "2024-08-15T07:22:22Z",
            "startedAt": "2024-08-15T07:22:22Z",
            "stoppedAt": "2024-08-15T07:22:25Z",
            "fullyChargedAt": null,
            "failedAt": null,
            "timeoutAt": null,
            "state": "completed",
            "consumedKwh": 0.0,
            "kwhLimit": null,
            "startMeterKwh": 7955.649,
            "endMeterKwh": 7955.649,
            "cost": 0,
            "price": 0,
            "priceLimit": null,
            "averagePricePerKwh": 0,
            "averageCo2PerKwh": 0.0,
            "averageRenewablePerKwh": 0.0,
            "failureReason": null,
            "stopReason": "regular state change",
            "note": null,
            "currency": {
                "identifier": "dkk",
                "name": "Danish kroner",
                "decimals": 2
            },
            "soc": null,
            "socLimit": null
        }
    ],
    "meta": {
        "itemCount": 2,
        "currentPage": 0,
        "perPage": 10,
        "totalPageCount": 1,
        "totalItemCount": 2
    }
}

@tougher
Copy link
Contributor Author

tougher commented Oct 28, 2024

D'oh - I forgot about the tests.

Copy link
Owner

@MattJeanes MattJeanes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks great, but the tests have broken because of it that need to be fixed

See TeslaMateAgile.Tests/Services/MontaServiceTests.cs lines 59 and 106

I'd just make the URL a static value incorporating the 24 hour shift rather than being smart about it like e.g. &fromDate=2024-10-10T00:00:00Z etc

@MattJeanes
Copy link
Owner

Also I think we can just set a static 24 hours here, we don't want to add config options for everything - if we see in future that having it configurable would be valuable then we can do that. The Tibber, Energinet and Awattar services all do similar things with fixed times to add.

Copy link
Owner

@MattJeanes MattJeanes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@MattJeanes MattJeanes merged commit 448b461 into MattJeanes:main Oct 28, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants