iantrich / restriction-card

🔒 Apply restrictions to Lovelace cards
MIT License
259 stars 22 forks source link

Don't require click to unlock if condition isn't met #40

Closed xCJPECKOVERx closed 3 years ago

xCJPECKOVERx commented 3 years ago

Currently when a card is restricted and a condition is set, if the condition is not met then the unlock method is not required. However, the lock icon is still displayed, and a single click is still needed to unlock the card.

For example, I have a switch set up for my PC. I would like a confirm dialog when turning off the PC, but not when turning it on. Therefore, I have a restriction card that has a confirm restriction along with a condition:

- type: 'custom:restriction-card'
  row: true
  restrictions:
    confirm:
      condition:
        entity: switch.PC
        value: 'on'
      text: Turn off PC?
  card:
    entity: switch.PC

Preferably, when the condition is not on (PC is off) the lock overlay and required click would not be present. This way I have direct access to the switch and can turn it on with a single click.

I'm not sure if this should be a feature request or a bug report, since it appears that the logic in render() that returns the overlay div should be taking care of this.

iantrich commented 3 years ago

Put the condition at the top level of the configuration

- type: 'custom:restriction-card'
  row: true
  condition:
    entity: switch.PC
    value: 'on'
  restrictions:
    confirm:
      text: Turn off PC?
  card:
    entity: switch.PC