There are a number of cases when it is not desirable for a RESTful integration in certain conditions to attempt to contact the HTTP resource. For example:
in my case, I have a number of input_text helpers that store URLs for instances of the RESTful integration, but when HA is starting up it attempts to make HTTP requests before the helpers are ready, resulting in numerous log messages about “unknown” not being a valid URL.
What I have in mind is a template that evaluates to on/off. When it is off, the HTTP request is not attempted and all entities in that instance of the RESTful integration are ‘unavailable’. When it is on, things proceed as today.
In case 2 above, the template would be something like {{ has_value(‘input_text.url’) }}
Thanks @koying but the sensor availability templates are not evaluated until after the HTTP request is done. I am trying to stop the HTTP request being attempted when it is not possible to do so.
Ah, right you are.
That FR might actually ask for availability to be moved and/or duplicated at the resource level (and to be evaluated before fetching).
Yes, that’s what I meant. I first thought of it as “resource availability” but didn’t use the word “availability” because the sensor availability templates are evaluated after the data has been obtained (in fact after the state has been evaluated) whereas the idea here is to control whether there is any attempt to access the data. So, I wrote it as enable/disable. If there is another integration with an equivalent feature I would copy that, but I don’t know of one.
Mmm… What makes you think so?
Purely functionally, It seems to make sense to check availability at the resource level here, probably more than at the sensor level tbh.
Because, core has taken a firm stance at “Not logically (with an automation) modifying things in configuration”. Therefore a service wouldn’t be added. Frenck made spook partially because of this stance.
As for how you’d do it, with spook you’d use the enable/disable polling for that entity.
If I understand what is meant by “service call” correctly, none is required. The implementation can be done entirely within homeassistant/components/rest by:
RestData.async_update() in homeassistant/components/rest/data.py evaluates the “enablement” template and, if false, returns with self.data=None and a property indicating why self.data is None;
async_setup_platform() in sensor.py and binary_sensor.py check for that property and do not raise
PlatformNotReady if it is set to indicate that enablement failed: this ensures that the sensors exists but have a state of unavailable.
@petro does this affect your view about its suitability for core?