Skip to content

Commit

Permalink
add climate+light conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
niels committed Jan 1, 2021
1 parent 7e9aa2c commit f52e91a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
47 changes: 46 additions & 1 deletion src/standard-configuration/climate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { levelVariable, listVariable } from '../actionVariables';
import { ActionConfig } from '../types';
import { HomeAssistant, LocalizeFunc } from 'custom-card-helpers';
import { computeStateDisplay, HomeAssistant, LocalizeFunc } from 'custom-card-helpers';
import { HassEntity } from 'home-assistant-js-websocket';
import { localize } from '../localize/localize';

Expand Down Expand Up @@ -194,3 +194,48 @@ export const climateActions = (

return actions;
};


export const climateStates = (hass: HomeAssistant, stateObj: HassEntity) => {
const modeList = [
{
value: 'off',
icon: 'hass:power-off',
name: hass.localize('state.climate.off'),
},
{
value: 'heat',
icon: 'hass:fire',
name: hass.localize('state.climate.heat'),
},
{
value: 'cool',
icon: 'hass:snowflake',
name: hass.localize('state.climate.cool'),
},
{
value: 'heat_cool',
icon: 'hass:thermometer',
name: hass.localize('state.climate.heat_cool'),
},
{
value: 'auto',
icon: 'hass:autorenew',
name: hass.localize('state_attributes.climate.auto'),
},
{
value: 'dry',
icon: 'hass:water-percent',
name: hass.localize('state.climate.dry'),
},
{
value: 'fan_only',
icon: 'hass:fan',
name: hass.localize('state.climate.fan_only'),
},
];
if (stateObj && stateObj.attributes.hvac_modes && Array.isArray(stateObj.attributes.hvac_modes)) {
return modeList.filter(e => stateObj.attributes.hvac_modes.includes(e.value));
}
return modeList;
};
16 changes: 15 additions & 1 deletion src/standard-configuration/light.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HassEntity } from 'home-assistant-js-websocket';
import { levelVariable } from '../actionVariables';
import { ActionConfig } from '../types';
import { HomeAssistant } from 'custom-card-helpers';
import { computeStateDisplay, HomeAssistant } from 'custom-card-helpers';
import { localize } from '../localize/localize';

export const lightActions = (hass: HomeAssistant, stateObj?: HassEntity): ActionConfig[] => {
Expand Down Expand Up @@ -39,3 +39,17 @@ export const lightActions = (hass: HomeAssistant, stateObj?: HassEntity): Action

return actions;
};


export const lightStates = (hass: HomeAssistant, stateObj: HassEntity) => [
{
value: "off",
name: computeStateDisplay(hass.localize, { ...stateObj, state: "off" }, hass.language),
icon: "hass:lightbulb-off"
},
{
value: "on",
name: computeStateDisplay(hass.localize, { ...stateObj, state: "on" }, hass.language),
icon: "hass:lightbulb"
}
];
6 changes: 6 additions & 0 deletions src/standard-configuration/standardStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { inputBooleanStates } from './input_boolean';
import { switchStates } from './switch';
import { personStates } from './person';
import { fanStates } from './fan';
import { lightStates } from './light';
import { climateStates } from './climate';

export function standardStates(entity_id: string, hass: HomeAssistant) {
const domain = computeDomain(entity_id);
Expand All @@ -17,6 +19,8 @@ export function standardStates(entity_id: string, hass: HomeAssistant) {
return alarmControlPanelStates(hass, stateObj);
case 'binary_sensor':
return binarySensorStates(hass, stateObj);
case 'climate':
return climateStates(hass, stateObj);
case 'cover':
return coverStates(hass, stateObj);
case 'fan':
Expand All @@ -25,6 +29,8 @@ export function standardStates(entity_id: string, hass: HomeAssistant) {
return inputBooleanStates(hass, stateObj);
case 'switch':
return switchStates(hass, stateObj);
case 'light':
return lightStates(hass, stateObj);
case 'lock':
return lockStates(hass, stateObj);
case 'person':
Expand Down

0 comments on commit f52e91a

Please sign in to comment.