Skip to content

Commit

Permalink
feat: Move top level layout options in control to new layout option
Browse files Browse the repository at this point in the history
BREAKING CHANGE: control._names, control._icons, control._headings are
moved to layout.mode.{names,icons,headings}
  • Loading branch information
nervetattoo committed Apr 5, 2021
1 parent b224ef7 commit 629fc36
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ resources:
- `temperature`: _bool_ (Default to `false`)
- `state`: _bool_ (Default to `false`)
- `control` _object|array_ (From 0.27)
- `_names` _bool_: Show mode names or not. Defaults to true
- `_icons` _bool_: Show mode icons or not. Defaults to true
- `_headings` _bool_: Show a heading for each mode button row. Defaults to true
- `{type}` _object|bool_: The key of the mode type (hvac, preset, fan, swing)
- `_name` _string_: Override the name of the mode type
- `_hide_when_off` _bool_: Hides the mode type selection row when the entity is off. Defaults to false shown
Expand Down
48 changes: 29 additions & 19 deletions src/config/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,46 @@ import { LooseObject, ConfigSensor } from '../types'
import { Service } from './service'
import { Setpoints } from './setpoints'

export interface ControlField {
export enum MODES {
HVAC = 'hvac',
FAN = 'fan',
PRESET = 'preset',
SWING = 'swing',
}

type ControlItem =
| boolean
| {
name?: string | false
icon?: string | false
}

export type ControlField = Record<string, ControlItem> & {
_name: string
_hide_when_off: boolean
icon: string
[key: string]:
| string
| boolean
| {
name: string | boolean
icon: string | boolean
}
}

export interface ControlObject {
_names?: boolean
_icons?: boolean
_headings?: boolean
[key: string]: boolean | string | ControlField
type ControlObject = {
hvac: boolean | ControlField
fan: boolean | ControlField
preset: boolean | ControlField
swing: boolean | ControlField
}

export type ControlList = Array<string>

export interface CardConfig {
interface CardConfig {
entity?: string
header: false | HeaderConfig
control?: false | ControlObject | ControlList
control?: false | ControlObject | string[]
sensors?: false | Array<ConfigSensor>
setpoints?: Setpoints
decimals?: number
step_size?: number
step_layout?: 'row' | 'column'
layout?: {
mode: {
names: boolean
icons: boolean
headings: boolean
}
sensors: {
type: 'table' | 'list'
labels: boolean
Expand All @@ -53,3 +61,5 @@ export interface CardConfig {
state?: string
}
}

export { CardConfig }
4 changes: 2 additions & 2 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,14 @@ export default class SimpleThermostatEditor extends LitElement {
<div class="side-by-side">
<paper-dropdown-menu
label="Step Layout (optional)"
.configValue=${'step_layout'}
.configValue=${'layout.step'}
@value-changed="${this.valueChanged}"
class="dropdown"
>
<paper-listbox
slot="dropdown-content"
.selected=${Object.values(OptionsStepLayout).indexOf(
this.config.step_layout
this.config.layout?.step
)}
>
${Object.values(OptionsStepLayout).map(
Expand Down
27 changes: 10 additions & 17 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@ import parseHeader, { HeaderData, MODE_ICONS } from './config/header'
import parseSetpoints from './config/setpoints'
import parseService, { Service } from './config/service'

import { CardConfig, ControlField } from './config/card'
import { CardConfig, ControlField, MODES } from './config/card'

import {
ControlMode,
LooseObject,
Sensor,
HASS,
HVAC_MODES,
MODES,
} from './types'
import { ControlMode, LooseObject, Sensor, HASS, HVAC_MODES } from './types'

const DEBOUNCE_TIMEOUT = 1000
const STEP_SIZE = 0.5
Expand Down Expand Up @@ -210,19 +203,19 @@ export default class SimpleThermostat extends LitElement {
} else if (Array.isArray(this.config.control)) {
controlModes = buildBasicModes(this.config.control)
} else if (typeof this.config.control === 'object') {
const { _names, _icons, _headings, ...modes } = this.config.control
const { names, icons, headings } = this.config?.layout?.mode

if (typeof _names === 'boolean') {
this.modeOptions.names = _names
if (typeof names === 'boolean') {
this.modeOptions.names = names
}
if (typeof _icons === 'boolean') {
this.modeOptions.icons = _icons
if (typeof icons === 'boolean') {
this.modeOptions.icons = icons
}
if (typeof _headings === 'boolean') {
this.modeOptions.headings = _headings
if (typeof headings === 'boolean') {
this.modeOptions.headings = headings
}

const entries = Object.entries(modes)
const entries = Object.entries(this.config.control)
if (entries.length > 0) {
controlModes = entries
.filter(([type]) => supportedModeType(type))
Expand Down

0 comments on commit 629fc36

Please sign in to comment.