mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-22 16:56:35 +00:00
Don't show toggle always on more info (#11640)
This commit is contained in:
parent
806b1296b0
commit
63c9b3f830
@ -1,4 +1,4 @@
|
|||||||
import { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
|
||||||
export const canToggleDomain = (hass: HomeAssistant, domain: string) => {
|
export const canToggleDomain = (hass: HomeAssistant, domain: string) => {
|
||||||
const services = hass.services[domain];
|
const services = hass.services[domain];
|
||||||
|
@ -1,14 +1,30 @@
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { canToggleDomain } from "./can_toggle_domain";
|
import { canToggleDomain } from "./can_toggle_domain";
|
||||||
import { computeStateDomain } from "./compute_state_domain";
|
import { computeStateDomain } from "./compute_state_domain";
|
||||||
import { supportsFeature } from "./supports-feature";
|
import { supportsFeature } from "./supports-feature";
|
||||||
|
|
||||||
export const canToggleState = (hass: HomeAssistant, stateObj: HassEntity) => {
|
export const canToggleState = (hass: HomeAssistant, stateObj: HassEntity) => {
|
||||||
const domain = computeStateDomain(stateObj);
|
const domain = computeStateDomain(stateObj);
|
||||||
|
|
||||||
if (domain === "group") {
|
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") {
|
if (domain === "climate") {
|
||||||
return supportsFeature(stateObj, 4096);
|
return supportsFeature(stateObj, 4096);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,10 @@ describe("canToggleState", () => {
|
|||||||
turn_off: null,
|
turn_off: null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
states: {
|
||||||
|
"light.bla": { entity_id: "light.bla" },
|
||||||
|
"light.test": { entity_id: "light.test" },
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
it("Detects lights toggle", () => {
|
it("Detects lights toggle", () => {
|
||||||
@ -24,7 +28,11 @@ describe("canToggleState", () => {
|
|||||||
const stateObj: any = {
|
const stateObj: any = {
|
||||||
entity_id: "group.bla",
|
entity_id: "group.bla",
|
||||||
state: "on",
|
state: "on",
|
||||||
|
attributes: {
|
||||||
|
entity_id: ["light.bla", "light.test"],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.isTrue(canToggleState(hass, stateObj));
|
assert.isTrue(canToggleState(hass, stateObj));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user