Skip to content

Commit

Permalink
actually functional
Browse files Browse the repository at this point in the history
  • Loading branch information
iantrich committed Oct 16, 2019
1 parent 953c8b0 commit be0b4d2
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 20 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ Hey dude! Help me out for a couple of :beers: or a :coffee:!

## Restrictions Options

| Name | Type | Requirement | Description |
| ------- | ------ | ------------ | ------------------------------------ |
| confirm | object | **Optional** | Confirmation restriction. See below. |
| pin | object | **Optional** | Pin restriction. See below. |
| block | object | **Optional** | Block restriction. See below. |
| Name | Type | Requirement | Description |
| ------- | ------ | ------------ | ------------------------------------------- |
| confirm | object | **Optional** | Confirmation unlock restriction. See below. |
| pin | object | **Optional** | Pin code restriction. See below. |
| block | object | **Optional** | Block interaction restriction. See below. |
| hide | object | **Optional** | Hide card restriction. See below. |

## Confirm Options

Expand All @@ -57,6 +58,12 @@ Hey dude! Help me out for a couple of :beers: or a :coffee:!
| ---------- | ---- | ------------ | ------------------------------------------------------ |
| exemptions | list | **Optional** | List of exemption objects. See exemption object below. |

## Hide Options

| Name | Type | Requirement | Description |
| ---------- | ---- | ------------ | ------------------------------------------------------ |
| exemptions | list | **Optional** | List of exemption objects. See exemption object below. |

## Exemption Options

| Name | Type | Requirement | Description |
Expand Down
240 changes: 240 additions & 0 deletions dist/restriction-card.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import babel from 'rollup-plugin-babel';
import { terser } from "rollup-plugin-terser";

export default {
input: ['src/card.ts'],
input: ['src/restriction-card.ts'],
output: {
dir: './dist',
format: 'es',
Expand Down
1 change: 0 additions & 1 deletion src/editor.ts

This file was deleted.

19 changes: 15 additions & 4 deletions src/card.ts → src/restriction-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
LovelaceCardConfig
} from "custom-card-helpers";

@customElement("hui-restriction-card")
class HuiRestrictionCard extends LitElement implements LovelaceCard {
@customElement("restriction-card")
class RestrictionCard extends LitElement implements LovelaceCard {
@property() protected _config?: RestrictionCardConfig;
protected _hass?: HomeAssistant;

Expand Down Expand Up @@ -60,14 +60,25 @@ class HuiRestrictionCard extends LitElement implements LovelaceCard {
return html``;
}

if (
this._config.restrictions &&
this._config.restrictions.hide &&
(!this._config.restrictions.hide.exemptions ||
!this._config.restrictions.hide.exemptions.some(
e => e.user === this._hass!.user!.id
))
) {
return html``;
}

return html`
<div>
${this._config.exemptions &&
this._config.exemptions.some(e => e.user === this._hass!.user!.id)
? ""
: html`
<div @click=${this._handleClick} id="overlay">
<ha-icon icon="hass:lock-outline" id="lock"></ha-icon>
<ha-icon icon="mdi:lock-outline" id="lock"></ha-icon>
</div>
`}
${this.renderCard(this._config.card!)}
Expand Down Expand Up @@ -201,6 +212,6 @@ class HuiRestrictionCard extends LitElement implements LovelaceCard {

declare global {
interface HTMLElementTagNameMap {
"hui-restriction-card": HuiRestrictionCard;
"restriction-card": RestrictionCard;
}
}
23 changes: 14 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,35 @@ import { ActionConfig, LovelaceCardConfig } from "custom-card-helpers";

export interface RestrictionCardConfig extends LovelaceCardConfig {
restrictions?: RestrictionsConfig;
exemptions?: RestrictionTypeConfig[];
exemptions?: ExemptionConfig[];
card?: LovelaceCardConfig;
}

export interface RestrictionsConfig {
confirm?: ConfirmRestrictionTypeConfig;
confirm?: ConfirmRestrictionConfig;
pin?: PinRestrictionConfig;
block?: BlockTypeConfig;
block?: BlockRestrictionConfig;
hide?: HideRestrictionConfig;
}

export interface ConfirmRestrictionTypeConfig {
exemptions?: RestrictionTypeConfig[];
export interface ConfirmRestrictionConfig {
exemptions?: ExemptionConfig[];
}

export interface BlockTypeConfig {
exemptions?: RestrictionTypeConfig[];
export interface BlockRestrictionConfig {
exemptions?: ExemptionConfig[];
}

export interface HideRestrictionConfig {
exemptions?: ExemptionConfig[];
}

export interface PinRestrictionConfig {
code: string;
exemptions?: RestrictionTypeConfig[];
exemptions?: ExemptionConfig[];
}

export interface RestrictionTypeConfig {
export interface ExemptionConfig {
user: string;
}

Expand Down

0 comments on commit be0b4d2

Please sign in to comment.