Update custom .ui states

Posted on
Wed Dec 16, 2020 10:27 am
aldonc offline
Posts: 22
Joined: Jan 10, 2015

Update custom .ui states

Hi,
I'm doing a bit of work in anticipation of DarkSky going away and using GhostXML to pull down OpenWeather info. Most of the states created have .ui versions and I was trying to update those (to format with appropriate units) but they are private to the plugin. Is there any way to do that other than creating a bunch of variables?

I realize this isn't specifically a GhostXML topic but hoping you've dealt with this based on the FW thread about DarkSky/OpenWeather!

thanks,
Aldon

Posted on
Wed Dec 16, 2020 11:14 am
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Update custom .ui states

Hi Aldon - thanks for giving this a try. That's true; you can only change the value of the states and ui.states as the device "owner" (in this case, the plugin).

What I do in such circumstances is to use the Adapters Plugin. This doesn't get away from creating a bunch of Indigo objects, but at least it makes it more "native" (rather than writing code to change each one individually).

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

[My Plugins] - [My Forums]

Posted on
Wed Dec 16, 2020 11:30 am
aldonc offline
Posts: 22
Joined: Jan 10, 2015

Re: Update custom .ui states

Hi Dave,
Thanks for the reply. I had seen something about Adpaters a while back (maybe from you) and I worried that tit seemed like the plugin was dead in terms of development. I'll give it a try since, if it works for me, it may not matter if there's any more development.

Aldon

Posted on
Wed Dec 16, 2020 12:44 pm
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Update custom .ui states

In my opinion, the Adapters plugin is very robust. I think you'll find it's quite good.

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

[My Plugins] - [My Forums]

Posted on
Wed Dec 16, 2020 7:09 pm
aldonc offline
Posts: 22
Joined: Jan 10, 2015

Re: Update custom .ui states

Hi Dave, Seems like I can make Adapters work. Just to confirm, there needs to be an Adapter Device created for each item to format? For example a Device for each day's high temperature? Just want to be sure I'm not missing something obvious.

Also, do you have a working format code for a string result with dates? What I pulled from the help link throws errors using OpenWeather's unix timestamp - {:%Y-%m-%d}.

thanks again,
Aldon

Posted on
Wed Dec 16, 2020 7:50 pm
DaveL17 offline
User avatar
Posts: 5909
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Update custom .ui states

So it looks like Adapters doesn't do datetime values. I don't know what your original data format is, but in order to use the date/time format specifiers, you need the source data to be a datetime object (which Adapters doesn't support). Here are a couple of python examples:

Code: Select all
import datetime

x = float("1608157366")

x = datetime.datetime.fromtimestamp(x)

print(u"{0:%Y-%m-%d}".format(x))
Here is one from a "full" timestamp value:

Code: Select all
import datetime

x = "1970-01-01 12:34:56.12345"

x = datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S.%f")

print(u"{0:%Y-%m-%d}".format(x))
(your format specifier was correct.)

At some point I may look into whether the Adapters plugin could be changed to include datetimes.

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

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest

cron