From a1b44c35223f0ff0b91703643940dee6d399d6be Mon Sep 17 00:00:00 2001 From: Ryan Adolf Date: Sun, 12 Sep 2021 12:04:17 -0700 Subject: [PATCH] Add state attribute for computing end time --- README.md | 10 +++++++++- src/helpers.ts | 1 + src/types.ts | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bdb35b5..491ffca 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,15 @@ duration: units: minutes # Since the slider state is a number like 10.0 ``` -#### 7. If your entity doesn't meet these criteria... +#### 7. My end time comes from the entity's state + +End times and durations can use any of the types `attribute`, `fixed`, `entity` (you've seen these 3 before) and `state`! The `state` type uses the entity's current state. Let's say we have a timer who's state is the time it will go off, like `2021-09-07T20:24:13+00:00`! Here's how to configure the card: + +```yaml +end_time: { state: true } +``` + +#### 8. If your entity doesn't meet these criteria... 🧡 please create an issue and tell me the entity so I can improve these instructions! ❤️️ diff --git a/src/helpers.ts b/src/helpers.ts index 31837b0..c61ee95 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -101,6 +101,7 @@ export const attribute = (hass: HomeAssistant, stateObj: HassEntity, attrib: Att if (!attrib) throw new Error('One of duration, start_time, or end_time was not fully specified. Make sure you set entity, fixed, or attribute'); if ('fixed' in attrib) return attrib.fixed; if ('entity' in attrib) return hass.states[attrib.entity].state; + if ('state' in attrib) return stateObj.state; return stateObj.attributes[attrib.attribute]; } diff --git a/src/types.ts b/src/types.ts index 7ba5628..b310e80 100644 --- a/src/types.ts +++ b/src/types.ts @@ -37,6 +37,7 @@ interface modsConfig extends styleConfig { type AttributeType = | { attribute: string } | { entity: string } + | { state: any } | { fixed: number }; export type AttributeConfig = AttributeType & { units?: "duration" | "hours" | "minutes" | "seconds";