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

[renault] Renault more channels and HVAC ON / toggle charge mode #12095

Merged
merged 34 commits into from
Feb 12, 2022

Conversation

dougculnane
Copy link
Contributor

The initial Renault binding added in openhab 3.2 had a few basic channels. This update adds more channels and the ability to interact with the car.

Turning the HVAC ON allows users to pre-heat their cars.

Switching charge mode allows users to control the charge limit of their cars without a smart charger.

There is much discussion, testing and feedback to these changes in the forum starting here: https://community.openhab.org/t/betatest-renault-ze-services-binding/72226/127

@lolodomo kindly reviewed inital contribution. I have tried to continue the style of his feedback with the additional changes.

The HVAC ON command to the car and wait for a response from the server is a problem i have tried to solve in a not too confusing way. I hope this is OK. The status is only polled every 10 minutes so feedback that the HVAC is really ON needs a delayed response to give the car and MyRenault server time to react....

cweitkamp and others added 24 commits November 29, 2021 20:40
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
…t rule.

Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
@lolodomo lolodomo added the enhancement An enhancement or new feature for an existing add-on label Jan 23, 2022
Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
@lolodomo
Copy link
Contributor

I will review this PR.

Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
@dougculnane
Copy link
Contributor Author

@lolodomo Thank you for reviewing this update to the binding.

The HVAC ON command to the car and wait for a response from the server might not be the most openHAB way to do this. If you know of a better technique please let me know.

@dougculnane
Copy link
Contributor Author

@lolodomo The binding is working well (again). However there are some strange Renault API behaviours that I do not fully understand.

I will do the mvn i18n:generate-default-translations command and get the German and English translations done soon.

I am still not sure how to avoid generic Exceptions without a massive catch list or a dead job task...

@lolodomo
Copy link
Contributor

lolodomo commented Feb 5, 2022

I will do the mvn i18n:generate-default-translations command and get the German and English translations done soon.

The German translation must not be part of this PR. It should be done in Crowdin.

I am still not sure how to avoid generic Exceptions without a massive catch list or a dead job task...

Let me check again, if you are in the case of scheduled task, this may be acceptable.

…-default-translations

Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
@lolodomo
Copy link
Contributor

lolodomo commented Feb 6, 2022

Let me check again, if you are in the case of scheduled task, this may be acceptable.

This is not code run in a regular scheduled task so I see no reason to not catch so largely.

Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
@dougculnane
Copy link
Contributor Author

@lolodomo I have pushed a list of errors that could be thrown. I am not sure if this is what you wanted me to do. I am concerned that a runtime error (like "SSL cert no long valid", or "Unknown host exception".... ) will throw a nasty error up the openHAB stack to be handled elsewhere. I am not sure I can for-see all the unforeseen situations.... if I try to list them. Maybe I misunderstand this or maybe openHAB handles these situations better. Please let me know what you are after if my push is not it.

@dougculnane
Copy link
Contributor Author

@lolodomo I have a bug report here: https://community.openhab.org/t/betatest-renault-ze-services-binding/72226/176?u=doug_culnane

Basically it is suggested that Number:Lengths should be set using meter values and not the KM value. Is this maybe a binding issue I should change or an openHAB bug that some components assume meters?

@lolodomo
Copy link
Contributor

You have to check / log the value returned by the API. Is this value in meters or kilometers. Your code assumes it is in kilometers.
If you have already something in your code allowing to log the API response, ask the user to provide this log to you.

@dougculnane
Copy link
Contributor Author

@lolodomo Thanks for your response. I can reproduce the bug I think and I think it is an "analysis screen" issue.

https://community.openhab.org/t/betatest-renault-ze-services-binding/72226/180?u=doug_culnane

Therefore I will not try to patch the binding at this stage.

@lolodomo
Copy link
Contributor

Thanks for your response. I can reproduce the bug I think and I think it is an "analysis screen" issue.

What is important for you is the state value of the linked item.

@dougculnane
Copy link
Contributor Author

What is important for you is the state value of the linked item.

This is good I have check the display value and it is correct and the mysql stored value which is also correct (in meters)

| 2022-02-10 13:17:45 | 7642230 |
| 2022-02-10 16:28:39 | 7642540 |
| 2022-02-10 16:58:49 | 7647060 |
| 2022-02-10 17:08:53 | 7650330 |
| 2022-02-10 17:18:57 | 7653790 |
+---------------------+---------+
258 rows in set (0.001 sec)

MariaDB [openhab]> select * from item0989;

@lolodomo
Copy link
Contributor

This is good I have check the display value and it is correct and the mysql stored value which is also correct (in meters)

Why in meters ? Your code assumes that the API value is in kilometers if you provide unit KILO(METER) when building the QuantityType.
Of course if you provide a pattern requesting the display in meters, mainUI will show meters.
Regarding persistence, as UoM is not managed by persistence, my feeling is that it should store the value you provide in the updateState, so a value in kilimeters.

@lolodomo
Copy link
Contributor

The first step is to check the unit of the value returned by the API. Any other discussion is probably just loss of time ;)

@dougculnane
Copy link
Contributor Author

dougculnane commented Feb 10, 2022

The API returns KM (totalMileage) and the value we want to display is in KM.

This is an example response I just got from the API:

{
    "data":{
        "type":"Car",
        "id":"VIN-ABC123",
        "attributes":{
            "fuelAutonomy":0.0,
            "fuelQuantity":0.0,
            "totalMileage":7653.79
        }
    }
}

The totalMileage is km. I use this value with the KM unit. But I guess... the value is converted to a standard meters value as a Number:Length type...???

@lolodomo
Copy link
Contributor

The totalMileage is km. I use this value with the KM unit. But I guess... the value is converted to a standard meters value as a Number:Length type...???

There is no standard meters value.
Maybe a conversion specific to the mySQL persistence service?

@dougculnane
Copy link
Contributor Author

@lolodomo OK there may be issues but they are outside the scope of this binding and pull request I guess.

Did you get a chance to look at the exception handling? Do you want to chat about this? We can do a quick meeting now if that would save time. I am not sure how i can resolve this.

@lolodomo
Copy link
Contributor

Just check if KILO(METER( is the proper unit definition. I am almost sure other bindings are using kilometers.

I will finish the review probably tomorrow or Saturday,

@dougculnane
Copy link
Contributor Author

dougculnane commented Feb 10, 2022

Tesla uses MILEs...

ODOMETER("odometer", "odometer", DecimalType.class, false) {
@Override
public State getState(String s, TeslaChannelSelectorProxy proxy, Map<String, String> properties) {
State someState = super.getState(s);
BigDecimal value = ((DecimalType) someState).toBigDecimal();
return new QuantityType<>(value, ImperialUnits.MILE);
}
},

Volvo use KILO(METRE)

return status.odometer != UNDEFINED ? new QuantityType<>((double) status.odometer / 1000, KILO(METRE))

@lolodomo
Copy link
Contributor

So your code is correct IMHO.

Maybe there is a bug in MainUI.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/betatest-renault-ze-services-binding/72226/182

Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

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

LGTM

@lolodomo
Copy link
Contributor

I am concerned that a runtime error (like "SSL cert no long valid", or "Unknown host exception".... ) will throw a nasty error up the openHAB stack to be handled elsewhere.

You are using Jetty HTTP client in your code and you are handling the exceptions that can be thrown by Jetty calls. So I don't understand what exception you could loose.

@lolodomo lolodomo merged commit 605c061 into openhab:main Feb 12, 2022
@lolodomo lolodomo added this to the 3.3 milestone Feb 12, 2022
volkmarnissen pushed a commit to volkmarnissen/openhab-addons that referenced this pull request Mar 3, 2022
…nhab#12095)

* [renault] Add more channels to Renault Binding.
* [renault] Improve example rule to reduce API use.

Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this pull request Apr 27, 2022
…nhab#12095)

* [renault] Add more channels to Renault Binding.
* [renault] Improve example rule to reduce API use.

Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Nick Waterton <n.waterton@outlook.com>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this pull request Jun 29, 2022
…nhab#12095)

* [renault] Add more channels to Renault Binding.
* [renault] Improve example rule to reduce API use.

Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
andan67 pushed a commit to andan67/openhab-addons that referenced this pull request Nov 6, 2022
…nhab#12095)

* [renault] Add more channels to Renault Binding.
* [renault] Improve example rule to reduce API use.

Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Nov 12, 2022
…nhab#12095)

* [renault] Add more channels to Renault Binding.
* [renault] Improve example rule to reduce API use.

Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
psmedley pushed a commit to psmedley/openhab-addons that referenced this pull request Feb 23, 2023
…nhab#12095)

* [renault] Add more channels to Renault Binding.
* [renault] Improve example rule to reduce API use.

Signed-off-by: Culnane Douglas <douglas.culnane@extern.a1.at>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants