ottopaulsen / MMM-Tibber

Show data from Tibber in MagicMirror
MIT License
33 stars 11 forks source link

Support for multiple houses #60

Open oysteinhagenpettersen opened 1 month ago

oysteinhagenpettersen commented 1 month ago

I started hacking away on a fork to support running multiple instances (house + cabin) of the module in the same MagicMirror setup. Hoping that you are open for a PR containing these changes. Sounds like a good plan?

ottopaulsen commented 1 month ago

I am happy to get PRs, so please go on, but discussing the changes first would be nice. I assume this is only about running the same module multiple times in the same MM. I haven't tried that, but that would be a good thing, and a nice way to solve such a case.

oysteinhagenpettersen commented 1 month ago

My use case involves having two separate instances of the module in the same MagicMirror (MM) for both my house and cabin. I assume others might have similar setups.

According to the MagicMirror documentation, each module can only have one node helper. Therefore, the node helper needs to be updated to support requests from multiple instances and respond with information that allows each instance to determine whether the update from the Tibber API is relevant to them.

The main change involves introducing an instance ID. This ID is used when the client (MMM-Tibber) communicates with the node helper via socket communication. The house ID serves as the instance ID, which is included in the message and extracted on the node helper side.

When the node helper sends Tibber data or subscription data back to the clients (MMM-Tibber), it attaches the same instance ID to the message. Each client then checks the instance ID to see if the update is meant for them. If it is, they update their view; if not, they ignore the update.

Let me know and I will open a PR so you can review the change.

ottopaulsen commented 1 month ago

Please do :-)