Hi All,
I’m working on this custom alarm project and have kind of architectural question here.
The alarm consists of two parts - the custom HA platform that has all data and logic in it and a Polymer-based web interface that let users interact with the component (arm/disarm/change settings).
The Polymer-based object knows about hass and my component and therefore can call services or access the component’s attributes.
It works ok for most things, but here is the real world scenario:
User clicks ARM button of the web interface, but we want to display a warning if there are any active sensors and ask whether they want to cancel arming or carry on anyway.
The current implementation is to get a list of all sensors from the component (via its attributes), upon arming check their states and display a prompt if necessary.
The trouble is to do all this the web interface should have a lot of up-to-date information that the component already has AND should implement some logic (what sensors to check, for example) when it’s much easier to encapsulate all that on the component level (it actually has a function to check open sensors, but I have to have another one in the web interface component class).
That is because the communication between the component and the web interface is limited by exposing its attributes and services, but sometimes something like a function call (i.e requests with some incoming data that produces a useable result) is required to provide a feedback from the component, which we cannot have when using service calls.
Ideally, for my scenario it would be great to implement something like this:
- User clicks the ARM button
- web component asks the HA component for a list of open sensors (just strings)
- if the list isn’t empty, display it and ask if we proceed or cancel
Is there anything in HA that would allow to achieve what I want?
Or any advise on the approach itself?
On a slightly side (but related) note - how to make some component-level data to the web interface?
For example, to be able to call the component’s service web interface should know domain and service name and currently it is hardcoded in .htlm (script).
I have both values in the custom component .py file, but don’t want to expose them as device_state_attributes results as it is intended to return state-related attributes (or that’s not true?).
What are the options here?