magico13 / PyEmVue

Python Library for the Emporia Vue Energy Monitor
MIT License
185 stars 36 forks source link

Use pydantic #73

Closed virgesmith closed 2 months ago

virgesmith commented 3 months ago

I'm using this package directly and via HA and felt I could contribute,

I noticed you're already using pydantic in the simulator code, and I thought the rest of the code would benefit - getting rid or all the manual json de/serialising boilerplate. It's a big change so I've made a start by converting PyEmVue.get_customer_details and PyEmvue.get_chart_usage for this PR , I am working on the rest separately, if you're interested let me know.

Also tweaked the Scale and Units enums so you don't have to explicitly use the value property

PS Not sure how you go about testing... didnt find any obvious tests or developer docs...

magico13 commented 2 months ago

Apologies for taking so long to get back to you. Interesting, definitely an improvement over all the manual conversions. If you have the rest I'm definitely interested. Should I wait for that before merging this or would you like this merged in first? Not sure if there are any implications with having it half converted.

There's no formal testing at the moment, just some test scripts and running the module directly which runs through most of the different functions as a spot check.

virgesmith commented 2 months ago

Hi yes I'll close this PR and open a new one with all the changes. I think there will be some changes to the structure of outputs, and I'm not able to check everything locally, as I don't have e.g. changers or vehicles. It will likely impact the HA integration. It definitely needs careful checking/testing before merging