Skip to content

Commit

Permalink
feat: add climate controller
Browse files Browse the repository at this point in the history
  • Loading branch information
MHA committed Jun 25, 2021
1 parent c78b539 commit 6b54910
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/controllers/climate-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Controller } from './controller';

export class ClimateController extends Controller {
_step = 1;
_targetValue;

get _value(): number {
return this.stateObj.attributes.temperature;
}

set _value(value) {
this._hass.callService('climate', 'set_temperature', {
// eslint-disable-next-line @typescript-eslint/camelcase
entity_id: this.stateObj.entity_id,
temperature: value,
});
}

get _min(): number {
return this.stateObj.attributes.min_temp;
}

get _max(): number {
return this.stateObj.attributes.max_temp;
}

get isValuePercentage(): boolean {
return false;
}

get label(): string {
return `${this.value} ${this._hass.config.unit_system.temperature}`
/*if (this.percentage > 0) {
if (this.hasSlider) {
return `${this.percentage}%`
} else {
return this._hass.localize('component.fan.state._.on');
}
}
return this._hass.localize('component.fan.state._.off');*/
}

}
2 changes: 2 additions & 0 deletions src/controllers/get-controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computeDomain } from 'custom-card-helpers';
import { Domain, SliderButtonCardConfig } from '../types';
import { ClimateController } from './climate-controller';
import { Controller } from './controller';
import { CoverController } from './cover-controller';
import { FanController } from './fan-controller';
Expand All @@ -18,6 +19,7 @@ export class ControllerFactory {
[Domain.COVER]: CoverController,
[Domain.INPUT_BOOLEAN]: InputBooleanController,
[Domain.MEDIA_PLAYER]: MediaController,
[Domain.CLIMATE]: ClimateController,
};
if (typeof mapping[domain] === 'undefined') {
throw new Error(`Unsupported entity type: ${domain}`)
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export enum Domain {
COVER = 'cover',
INPUT_BOOLEAN = 'input_boolean',
MEDIA_PLAYER = 'media_player',
CLIMATE = 'climate',
}

export const ActionButtonConfigDefault: ActionButtonConfig = {
Expand Down Expand Up @@ -161,6 +162,15 @@ export const SliderConfigDefaultDomain: Map<string, SliderConfig> = new Map([
toggle_on_click: false,
force_square: false,
}],
[Domain.CLIMATE, {
direction: SliderDirections.LEFT_RIGHT,
background: SliderBackground.TRIANGLE,
use_state_color: false,
use_percentage_bg_opacity: false,
show_track: true,
toggle_on_click: false,
force_square: false,
}],
]);

export enum LightAttributes {
Expand Down

0 comments on commit 6b54910

Please sign in to comment.