Skip to content

Commit

Permalink
fix: getting target temps when set to auto (piitaya#20)
Browse files Browse the repository at this point in the history
closes piitaya#19
  • Loading branch information
ulic75 authored May 30, 2022
1 parent fce0bf5 commit 2ca0ee0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/cards/thermostat-card/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { formatNumber, HomeAssistant, UNIT_F } from "custom-card-helpers";
import { supportsFeature } from "../../ha/common/entity/supports-feature";
import { ClimateEntity } from "../../ha/data/climate";
import { isNumber } from "../../utils/number";

Expand All @@ -16,10 +17,22 @@ export const getStepSize = (hass: HomeAssistant, entity: ClimateEntity): number
return entity.attributes.target_temp_step ?? systemStep;
};

export const supportTargetTemperatureRange = (entity: ClimateEntity) => supportsFeature(entity, 2);

export const supportsCoolOnly = (entity: ClimateEntity) => {
const modes = entity.attributes.hvac_modes;
return !modes.includes("heat") && modes.includes("cool");
};

export const supportsHeatOnly = (entity: ClimateEntity) => {
const modes = entity.attributes.hvac_modes;
return modes.includes("heat") && !modes.includes("cool");
};

export const getTargetTemps = (entity: ClimateEntity): [number | undefined, number | undefined] => {
const { target_temp_high, target_temp_low, temperature } = entity.attributes;

if (entity.state === "heat") return [target_temp_low ?? temperature, undefined];
if (entity.state === "cool") return [undefined, target_temp_high ?? temperature];
return [target_temp_low, target_temp_high];
if (supportTargetTemperatureRange(entity)) return [target_temp_low, target_temp_high];
if (supportsHeatOnly(entity)) return [target_temp_low ?? temperature, undefined];
return [undefined, target_temp_high ?? temperature];
};

0 comments on commit 2ca0ee0

Please sign in to comment.