Jim Klimov
2021-Dec-03 00:24 UTC
[Nut-upsdev] Python and NUT (Was: Proposed discussion: standardization of Status Flags and Instant Commands for ECO mode)
Just in case, regarding the spin-off topic of Python scripting: note there is a sort of binding in NUT sources, as used in GUI app etc. I am not sure what practical state it is in, e.g. if it may need more attention for NUT data points and concepts added in recent years, but I suppose fixing it in upstream (if needed) is better than everyone reinventing their wheel ;) In master branch, it was recently fixed to pass self-test with both Python 2.x and 3.x (several sub-versions). Jim On Wed, Dec 1, 2021, 19:06 Greg Troxel <gdt at lexort.com> wrote:> > Rob Crittenden <rcrit at greyoak.com> writes: > > > On 12/1/21 09:52, Edgar Fu? via Nut-upsdev wrote: > >>> I wrote python code, not yet published, that compares to "OL". > >> That will already break in the "OL RB" (online, replace battery) case. > > > > Or in my case currently: > > > > ups.status: ALARM OL RB > > Thanks to both of you and I get it I need to fix my code.... > > But for now, it's OL only and things are ok, or things are other than ok > and I need to pay attention, so not terrible. > _______________________________________________ > Nut-upsdev mailing list > Nut-upsdev at alioth-lists.debian.net > https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://alioth-lists.debian.net/pipermail/nut-upsdev/attachments/20211203/f39ab4da/attachment.htm>
Jim Klimov <jimklimov at gmail.com> writes:> Just in case, regarding the spin-off topic of Python scripting: note there > is a sort of binding in NUT sources, as used in GUI app etc. > > I am not sure what practical state it is in, e.g. if it may need more > attention for NUT data points and concepts added in recent years, but I > suppose fixing it in upstream (if needed) is better than everyone > reinventing their wheel ;) > > In master branch, it was recently fixed to pass self-test with both > Python 2.x and 3.x (several sub-versions).Thanks for pointing that out. I had found it in the last release, and then found the master branch fixed versions. I will see about making any enhancements there and submitting them; you are entirely right that any parsing and utility functions belong there. I also intend to publish my code someplace. It just checks status every 2s and reports json over mqtt, but it only sends a report if there is a meaningful change or a minute has passed. This avoids spamming Home Assistant recorder database with every 2s voltage readings, but reports immediately if it goes on battery or line voltage drops to 0. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 194 bytes Desc: not available URL: <http://alioth-lists.debian.net/pipermail/nut-upsdev/attachments/20211202/f03da08c/attachment.sig>
Roger Price
2021-Dec-04 11:49 UTC
[Nut-upsdev] Python and NUT (Was: Proposed discussion: standardization of Status Flags and Instant Commands for ECO mode)
On Fri, 3 Dec 2021, Jim Klimov via Nut-upsdev wrote:> Just in case, regarding the spin-off topic of Python scripting: note there is > a sort of binding in NUT sources, as used in GUI app etc.> I am not sure what practical state it is in, e.g. if it may need more > attention for NUT data points and concepts added in recent years,...If I remember correctly, the "binding" proposed is object oriented. Python is now de-emphasizing OO in order to attract more interest. Does the NUT project need to support Object Orientation when NUT is essentially event oriented?> In master branch, it was recently fixed to pass self-test with both Python 2.x > and 3.x (several sub-versions).Python 2 support ended on 2020-01-01 and now has status "end-of-life". I don't see any need to support it in NUT.> ...but I suppose fixing it in upstream (if needed) is better than everyone > reinventing their wheel ;)I wrote a Python replacement for upsmon, upssched and upssched-cmd. It introduces the concept of groups of UPS's with different groups having different behaviours. For example heartbeat dummy UPS's have their own group since there is no need to log heartbeat status changes. The biggest wheel I re-invented was the decoding of the new configuration file. I used PLY (Python Lex-Yacc) by David Beazley. The advantage is that it doesn't require separate Lex and Yacc specificationn files, but the result is difficult to read, and if I were to do it again I would look for a real Lex and Yacc. Roger