Skip to content
This repository was archived by the owner on Mar 9, 2023. It is now read-only.

Commit 512a23d

Browse files
committed
Availability template added
1 parent 5d9b7af commit 512a23d

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ cover:
4242
send_stop_at_ends: False #optional
4343
always_confident: False #optional
4444
device_class: garage #optional
45+
availability_template: "{{ is_state('binary_sensor.rfbridge_status', 'on') }}" #optional
4546
```
4647
4748
**OR**:
@@ -65,6 +66,7 @@ Optional settings:
6566
- `send_stop_at_ends` defaults to `False`. If set to `True`, the Stop script will be run after the cover reaches to 0 or 100 (closes or opens completely). This is for people who use interlocked relays in the scripts to drive the covers, which need to be released when the covers reach the end positions.
6667
- `always_confident` defaults to `False`. If set to `True`, the calculated state will always be assumed to be accurate. This mainly affects UI components - for example, if the cover is fully opened, the open button will be disabled. Make sure to [set](#cover_rf_time_basedset_known_position) the current state after first setup and only use this entity to control the covers. Not recommended to be `True` for RF-based covers.
6768
- `device_class` defaults to `shutter` if not specified. See the docs for availale [cover device classes](http://dev-docs.home-assistant.io/en/master/api/components.html#homeassistant.components.cover.CoverDeviceClass).
69+
- `availability_template` if not specified will make the cover always available. You can use a template returning `True` or `False` in order to toggle availability of the cover based on other elements. Useful to link with the connection status of your RF Bridge or relays device.
6870

6971
### Example scripts.yaml entry
7072
#### RF covers

custom_components/cover_rf_time_based/cover.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
SERVICE_CLOSE_COVER,
2424
SERVICE_OPEN_COVER,
2525
SERVICE_STOP_COVER,
26+
STATE_UNAVAILABLE,
2627
)
2728

2829
import homeassistant.helpers.config_validation as cv
@@ -45,6 +46,7 @@
4546
CONF_CLOSE_SCRIPT_ENTITY_ID = 'close_script_entity_id'
4647
CONF_STOP_SCRIPT_ENTITY_ID = 'stop_script_entity_id'
4748
CONF_COVER_ENTITY_ID = 'cover_entity_id'
49+
CONF_AVAILABILITY_TPL = 'availability_template'
4850
ATTR_CONFIDENT = 'confident'
4951
ATTR_ACTION = 'action'
5052
ATTR_POSITION_TYPE = 'position_type'
@@ -63,6 +65,7 @@
6365
vol.Optional(CONF_SEND_STOP_AT_ENDS, default=DEFAULT_SEND_STOP_AT_ENDS): cv.boolean,
6466
vol.Optional(CONF_ALWAYS_CONFIDENT, default=DEFAULT_ALWAYS_CONFIDENT): cv.boolean,
6567
vol.Optional(CONF_DEVICE_CLASS, default=DEFAULT_DEVICE_CLASS): DEVICE_CLASSES_SCHEMA,
68+
vol.Optional(CONF_AVAILABILITY_TPL): cv.template,
6669
}
6770
)
6871

@@ -125,7 +128,19 @@ def devices_from_config(domain_config):
125128
send_stop_at_ends = config.pop(CONF_SEND_STOP_AT_ENDS)
126129
always_confident = config.pop(CONF_ALWAYS_CONFIDENT)
127130
device_class = config.pop(CONF_DEVICE_CLASS)
128-
device = CoverTimeBased(device_id, name, travel_time_down, travel_time_up, open_script_entity_id, close_script_entity_id, stop_script_entity_id, cover_entity_id, send_stop_at_ends, always_confident, device_class)
131+
availability_template = config.pop(CONF_AVAILABILITY_TPL, None)
132+
device = CoverTimeBased(device_id,
133+
name,
134+
travel_time_down,
135+
travel_time_up,
136+
open_script_entity_id,
137+
close_script_entity_id,
138+
stop_script_entity_id,
139+
cover_entity_id,
140+
send_stop_at_ends,
141+
always_confident,
142+
device_class,
143+
availability_template)
129144
devices.append(device)
130145
return devices
131146

@@ -146,7 +161,19 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
146161

147162

148163
class CoverTimeBased(CoverEntity, RestoreEntity):
149-
def __init__(self, device_id, name, travel_time_down, travel_time_up, open_script_entity_id, close_script_entity_id, stop_script_entity_id, cover_entity_id, send_stop_at_ends, always_confident, device_class):
164+
def __init__(self,
165+
device_id,
166+
name,
167+
travel_time_down,
168+
travel_time_up,
169+
open_script_entity_id,
170+
close_script_entity_id,
171+
stop_script_entity_id,
172+
cover_entity_id,
173+
send_stop_at_ends,
174+
always_confident,
175+
device_class,
176+
availability_template):
150177
"""Initialize the cover."""
151178
from xknx.devices import TravelCalculator
152179
self._travel_time_down = travel_time_down
@@ -162,6 +189,7 @@ def __init__(self, device_id, name, travel_time_down, travel_time_up, open_scrip
162189
self._target_position = 0
163190
self._processing_known_position = False
164191
self._unique_id = device_id
192+
self._availability_template = availability_template
165193

166194
if name:
167195
self._name = name
@@ -195,9 +223,18 @@ def _handle_stop(self):
195223

196224
@property
197225
def unconfirmed_state(self):
198-
"""Return the assume state as a string to persist through restarts ."""
226+
"""Return the assume state as a string to persist through restarts."""
199227
return str(self._assume_uncertain_position)
200228

229+
@property
230+
def available(self):
231+
"""Return availability based on external template. Always available if no template specified."""
232+
if self._availability_template is None:
233+
return True
234+
else:
235+
self._availability_template.hass = self.hass
236+
return self._availability_template.async_render()
237+
201238
@property
202239
def name(self):
203240
"""Return the name of the cover."""

custom_components/cover_rf_time_based/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "cover_rf_time_based",
33
"name": "Cover Time Based RF (trigger script)",
4-
"version": "1.0.8",
4+
"version": "1.1.2",
55
"documentation": "https://github.com/nagyrobi/home-assistant-custom-components-cover-rf-time-based",
66
"iot_class": "assumed_state",
77
"requirements": [

info.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ With this component you can add a time-based cover. You have to set triggering s
99
- State can be updated based on independent, external sensors (for example a contact or reed sensor at closed or opened state)
1010
- State can mimic the operation based on external sensors (for example by monitoring the air for closing or opening RF codes) so usage in parrallel with controllers outside HA is possible
1111
- Ability to take care care of queuing the transmission of the codes and keeping an appropriate delay between them to minimize 'missed' commands
12-
- Can be used on top of any existing cover integration, or directly with Tasmota or ESPHome firmwares running on various ESP-based modules.
12+
- Can be used on top of any existing cover integration, or directly with ESPHome or Tasmota firmwares running on various ESP-based modules.
1313

1414
## Component authors & contributors
1515
"@davidramosweb",

0 commit comments

Comments
 (0)