Don't show toggle always on more info (#11640)

This commit is contained in:
Zack Barett 2022-02-14 09:21:46 -06:00 committed by GitHub
parent 806b1296b0
commit 63c9b3f830
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import { HomeAssistant } from "../../types";
import type { HomeAssistant } from "../../types";
export const canToggleDomain = (hass: HomeAssistant, domain: string) => {
const services = hass.services[domain];

View File

@ -1,14 +1,30 @@
import { HassEntity } from "home-assistant-js-websocket";
import { HomeAssistant } from "../../types";
import type { HassEntity } from "home-assistant-js-websocket";
import type { HomeAssistant } from "../../types";
import { canToggleDomain } from "./can_toggle_domain";
import { computeStateDomain } from "./compute_state_domain";
import { supportsFeature } from "./supports-feature";
export const canToggleState = (hass: HomeAssistant, stateObj: HassEntity) => {
const domain = computeStateDomain(stateObj);
if (domain === "group") {
return stateObj.state === "on" || stateObj.state === "off";
if (
stateObj.attributes?.entity_id?.some((entity) => {
const entityStateObj = hass.states[entity];
if (!entityStateObj) {
return false;
}
const entityDomain = computeStateDomain(entityStateObj);
return canToggleDomain(hass, entityDomain);
})
) {
return stateObj.state === "on" || stateObj.state === "off";
}
return false;
}
if (domain === "climate") {
return supportsFeature(stateObj, 4096);
}

View File

@ -10,6 +10,10 @@ describe("canToggleState", () => {
turn_off: null,
},
},
states: {
"light.bla": { entity_id: "light.bla" },
"light.test": { entity_id: "light.test" },
},
};
it("Detects lights toggle", () => {
@ -24,7 +28,11 @@ describe("canToggleState", () => {
const stateObj: any = {
entity_id: "group.bla",
state: "on",
attributes: {
entity_id: ["light.bla", "light.test"],
},
};
assert.isTrue(canToggleState(hass, stateObj));
});