File path to save CSV

Posted on
Sat May 02, 2020 2:44 pm
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

File path to save CSV

Hi Neil.

I noticed this afternoon that the plugin throws it's toys out of the pram if I ihaven't set a file path in the plugin config, but I have checked the box to save CSV in a device.

(Disclaimer: I did this on purpose to see if it broke!)

It's probably worth defaulting the CSV path to either your plugin folder or to ~/Documents/Octopus rather than to "" so that the CSV has somewhere to save to.

This is three lines of code I have in the Sense plugin which also has the option to save CSVs:
Code: Select all
self.csvPath = "{}/Preferences/Plugins/{}".format(indigo.server.getInstallFolderPath(), self.pluginId)
self.csvActive = "{}/Preferences/Plugins/{}/activeLog.csv".format(indigo.server.getInstallFolderPath(), self.pluginId)
self.csvDaily = "{}/Preferences/Plugins/{}/dailyLog.csv".format(indigo.server.getInstallFolderPath(), self.pluginId)
Ironically it's probably the only place in my plugins I've used .format() yet! Still getting my head around those and the new loggers!

Peeter

Posted on
Sun May 03, 2020 3:43 am
neilk offline
Posts: 714
Joined: Jul 13, 2015
Location: Reading, UK

Re: File path to save CSV

Peter,
Thanks and a good catch. Initially I was planning a single device and making the CSV a plugin level so the field was hidden unless checked. To be fair I hadn’t built any validation but when I moved to device level selection I should have thought of this. Thanks for the suggestion and the testing, I will fix.
Neil

Posted on
Sun May 03, 2020 4:31 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: File path to save CSV

howartp wrote:
Ironically it's probably the only place in my plugins I've used .format() yet! Still getting my head around those and the new loggers!

I found this reference of great help when I was learning the various .format() parameters: PyFormat: Using % and .format() for great good!

You're on your own with the new loggers. 8)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun May 03, 2020 5:47 am
howartp offline
Posts: 4559
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: File path to save CSV

DaveL17 wrote:
howartp wrote:
Ironically it's probably the only place in my plugins I've used .format() yet! Still getting my head around those and the new loggers!

I found this reference of great help when I was learning the various .format() parameters: PyFormat: Using % and .format() for great good!

You're on your own with the new loggers. 8)

Hehe, I have that link as a favourite/bookmark... does that help?


Sent from my iPhone using Tapatalk Pro

Posted on
Sun May 03, 2020 5:59 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: File path to save CSV

It does.

Just like having the bits to repair the gap between the driveway and the garage sitting on my workbench is akin to them being installed.

Or how having a salad with dinner counteracts the bowl of ice cream afterwards.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun May 03, 2020 7:43 am
neilk offline
Posts: 714
Joined: Jul 13, 2015
Location: Reading, UK

Re: File path to save CSV

Peter,
The sad thing was I had tested for the empty path, but then went ahead and wrote to it anyway. Doh. Anyway new version posted that implements your suggestion, and now also tests that a user supplied directory is actually writable. A couple of other things tidied.

Now moving on to Jon's suggestions to make the API calls once a day (or only when necessary) and to maintain a local results copy. I will also tidy up the counter intuitive use of UTC versus UK Local for the daily max, min and average. This will also help with adding consumption data in as well.

Thanks for the tip and the collaboration.

Neil

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest