Open comments for this post
Phew, another dev log!
For me, I had to figure out, what code should be part of the API, and what is the purpose of the coordinator?
I compared to ha-wiiu (https://github.com/wiiu-smarthome/ha-wiiu/blob/main/custom_components/nintendo_wiiu_ristretto/coordinator.py) as an example, and decided that:
- The “API” is the equivalent of “ha-wiiu” coordinator’s “Wii” object - it contains the methods for actually doing the requests. (For this project, Pywikibot does not use asyncio, so the “API” is our “wrapper” so the API calls do not interrupt the main loop)
- The “coordinator” is.. well, now it makes more sense to say it is a coordinator. It will poll the API when needed, but store data that is actually relevant.
So once I figured that out, it was off to me playing around with pywikibot to see how I could get site-specific user contributions. It seems that I will just have to count items in the contribution list, but for global site info (so, like all Wikimedia projects), it has its own accessible field.
So now I have a “0” in the sensor reading “Contributions”, which is correct because I have not made any edits to Test Wikipedia. I should soon be able to hook things up to other MediaWiki instances and see actual values!
Open comments for this post
Another small victory, but worth logging - turned out sign in is easier than I expected! (It only took me an hour to see if I wanted OAuth options, which I was going to use but I think basic client login will work)
Open comments for this post
Started taking the integration blueprint and did, something with it.
The MediaWiki API can take requests, which may be easier to code, but then the results have to be parsed. So I’ve decided to use the pywikibot library results, which sends things in a nicer way.
However, Home Assistant expects integrations to not make blocking calls.. and I think that actual network requests are made when you call for the operation. So if you make a page object, I don’t think it actually gets anything until you call page.extracts(). So the entity can’t call that, otherwise you get a blocking call. The coordinator needs to manage things specifically.
So this will eventually tie into making appropriate entities and representations of data - which, may be difficult, because HA does not expect entities to store the entire text of a Wikipedia article. But things like feeds are in RSS, so they may need separate handling - so basically, a bit of work to do of how this can be put into practice. I imagine a “Today’s featured article” kind of thing, but maybe that can be done simply with RSS feeds.. but I don’t think pywikibot handles that (it expects JSON responses). So, much more to dive into!