From 19a3810168ba015f650c005174c61b0b94170a9b Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Mon, 4 Mar 2024 15:22:04 +0100 Subject: [PATCH] Add sections dashboard to demo dashboard (#19976) --- demo/src/configs/demo-configs.ts | 1 + demo/src/configs/sections/entities.ts | 482 ++++++++++++++++++ demo/src/configs/sections/index.ts | 12 + demo/src/configs/sections/lovelace.ts | 280 ++++++++++ .../lovelace/sections/hui-grid-section.ts | 1 + 5 files changed, 776 insertions(+) create mode 100644 demo/src/configs/sections/entities.ts create mode 100644 demo/src/configs/sections/index.ts create mode 100644 demo/src/configs/sections/lovelace.ts diff --git a/demo/src/configs/demo-configs.ts b/demo/src/configs/demo-configs.ts index 07dca811f7..dacddf0944 100644 --- a/demo/src/configs/demo-configs.ts +++ b/demo/src/configs/demo-configs.ts @@ -4,6 +4,7 @@ import { energyEntities } from "../stubs/entities"; import { DemoConfig } from "./types"; export const demoConfigs: Array<() => Promise> = [ + () => import("./sections").then((mod) => mod.demoSections), () => import("./arsaboo").then((mod) => mod.demoArsaboo), () => import("./teachingbirds").then((mod) => mod.demoTeachingbirds), () => import("./kernehed").then((mod) => mod.demoKernehed), diff --git a/demo/src/configs/sections/entities.ts b/demo/src/configs/sections/entities.ts new file mode 100644 index 0000000000..ffb7389503 --- /dev/null +++ b/demo/src/configs/sections/entities.ts @@ -0,0 +1,482 @@ +import { convertEntities } from "../../../../src/fake_data/entity"; +import { DemoConfig } from "../types"; + +export const demoEntitiesSections: DemoConfig["entities"] = () => + convertEntities({ + "cover.living_room_garden_shutter": { + entity_id: "cover.living_room_garden_shutter", + state: "open", + attributes: { + current_position: 100, + device_class: "shutter", + friendly_name: "Living room garden shutter", + supported_features: 15, + }, + }, + "cover.living_room_graveyard_shutter": { + entity_id: "cover.living_room_graveyard_shutter", + state: "open", + attributes: { + current_position: 100, + device_class: "shutter", + friendly_name: "Living room graveyard shutter", + supported_features: 15, + }, + }, + "cover.living_room_left_shutter": { + entity_id: "cover.living_room_left_shutter", + state: "open", + attributes: { + current_position: 100, + device_class: "shutter", + friendly_name: "Living room left shutter", + supported_features: 15, + }, + }, + "cover.living_room_right_shutter": { + entity_id: "cover.living_room_right_shutter", + state: "open", + attributes: { + current_position: 100, + device_class: "shutter", + friendly_name: "Living room right shutter", + supported_features: 15, + }, + }, + "light.floor_lamp": { + entity_id: "light.floor_lamp", + state: "on", + attributes: { + min_color_temp_kelvin: 2000, + max_color_temp_kelvin: 6535, + min_mireds: 153, + max_mireds: 500, + supported_color_modes: ["color_temp", "xy"], + color_mode: "color_temp", + brightness: 178, + color_temp_kelvin: 2583, + color_temp: 387, + hs_color: [28.664, 69.597], + rgb_color: [255, 162, 77], + xy_color: [0.538, 0.389], + icon: "mdi:floor-lamp", + friendly_name: "Floor lamp", + supported_features: 44, + }, + }, + "light.living_room_spotlights": { + entity_id: "light.living_room_spotlights", + state: "on", + attributes: { + supported_color_modes: ["brightness"], + color_mode: "brightness", + brightness: 126, + icon: "mdi:ceiling-light-multiple", + friendly_name: "Living room spotlights", + supported_features: 32, + }, + }, + "light.bar_lamp": { + entity_id: "light.bar_lamp", + state: "on", + attributes: { + min_color_temp_kelvin: 2202, + max_color_temp_kelvin: 4504, + min_mireds: 222, + max_mireds: 454, + effect_list: ["None", "candle"], + supported_color_modes: ["color_temp"], + effect: null, + color_mode: null, + brightness: null, + color_temp_kelvin: null, + color_temp: null, + hs_color: null, + rgb_color: null, + xy_color: null, + mode: "normal", + dynamics: "none", + icon: "mdi:lightbulb-variant", + friendly_name: "Bar lamp", + supported_features: 44, + }, + }, + "sensor.living_room_temperature": { + entity_id: "sensor.living_room_temperature", + state: "22.8", + attributes: { + state_class: "measurement", + unit_of_measurement: "°C", + device_class: "temperature", + friendly_name: "Living room Temperature", + }, + }, + "media_player.living_room_nest_mini": { + entity_id: "media_player.living_room_nest_mini", + state: "off", + attributes: { + device_class: "speaker", + friendly_name: "Living room Nest Mini", + supported_features: 152461, + }, + }, + "cover.kitchen_shutter": { + entity_id: "cover.kitchen_shutter", + state: "open", + attributes: { + current_position: 100, + device_class: "shutter", + friendly_name: "Kitchen shutter ", + supported_features: 15, + }, + }, + "light.kitchen_spotlights": { + entity_id: "light.kitchen_spotlights", + state: "off", + attributes: { + supported_color_modes: ["brightness"], + color_mode: null, + brightness: null, + icon: "mdi:ceiling-light-multiple", + friendly_name: "Kitchen spotlights ", + supported_features: 32, + }, + }, + "light.worktop_spotlights": { + entity_id: "light.worktop_spotlights", + state: "off", + attributes: { + supported_color_modes: ["brightness"], + color_mode: null, + brightness: null, + icon: "mdi:ceiling-light-multiple", + friendly_name: "Worktop spotlights ", + supported_features: 32, + }, + }, + "binary_sensor.fridge_door": { + entity_id: "binary_sensor.fridge_door", + state: "off", + attributes: { + device_class: "door", + icon: "mdi:fridge", + friendly_name: "Fridge door", + }, + }, + "media_player.kitchen_nest_audio": { + entity_id: "media_player.kitchen_nest_audio", + state: "on", + attributes: { + device_class: "speaker", + friendly_name: "Kitchen Nest Audio", + supported_features: 152461, + }, + }, + "binary_sensor.tesla_wall_connector_vehicle_connected": { + entity_id: "binary_sensor.tesla_wall_connector_vehicle_connected", + state: "off", + attributes: { + device_class: "plug", + friendly_name: "Wall Connector Vehicle connected", + }, + }, + "sensor.tesla_wall_connector_session_energy": { + entity_id: "sensor.tesla_wall_connector_session_energy", + state: "16.3", + attributes: { + state_class: "total_increasing", + unit_of_measurement: "kWh", + device_class: "energy", + friendly_name: "Tesla Wall Connector Session energy", + }, + }, + "sensor.electric_meter_power": { + entity_id: "sensor.electric_meter_power", + state: "797.86", + attributes: { + state_class: "measurement", + unit_of_measurement: "W", + device_class: "power", + icon: "mdi:meter-electric", + friendly_name: "Electric meter Power", + }, + }, + "sensor.eletric_meter_voltage": { + entity_id: "sensor.eletric_meter_voltage", + state: "232.19", + attributes: { + state_class: "measurement", + unit_of_measurement: "V", + device_class: "voltage", + friendly_name: "Electric meter voltage", + }, + }, + "sensor.electricity_maps_grid_fossil_fuel_percentage": { + entity_id: "sensor.electricity_maps_grid_fossil_fuel_percentage", + state: "9.84", + attributes: { + state_class: "measurement", + country_code: "FR", + unit_of_measurement: "%", + attribution: "Data provided by Electricity Maps", + icon: "mdi:barrel", + friendly_name: "Electricity Maps Grid fossil fuel percentage", + }, + }, + "sensor.electricity_maps_co2_intensity": { + entity_id: "sensor.electricity_maps_co2_intensity", + state: "62.0", + attributes: { + state_class: "measurement", + country_code: "FR", + unit_of_measurement: "gCO2eq/kWh", + attribution: "Data provided by Electricity Maps", + friendly_name: "Electricity Maps CO2 intensity", + }, + }, + "sun.sun": { + entity_id: "sun.sun", + state: "above_horizon", + attributes: { + next_dawn: "2024-03-05T05:50:21.964405+00:00", + next_dusk: "2024-03-04T18:08:54.311334+00:00", + next_midnight: "2024-03-05T00:00:00+00:00", + next_noon: "2024-03-05T12:00:05+00:00", + next_rising: "2024-03-05T06:23:42.739159+00:00", + next_setting: "2024-03-04T17:35:26.271171+00:00", + elevation: 30.38, + azimuth: 204.42, + rising: false, + friendly_name: "Sun", + }, + }, + "sensor.moon_phase": { + entity_id: "sensor.moon_phase", + state: "waning_crescent", + attributes: { + options: [ + "new_moon", + "waxing_crescent", + "first_quarter", + "waxing_gibbous", + "full_moon", + "waning_gibbous", + "last_quarter", + "waning_crescent", + ], + device_class: "enum", + icon: "mdi:moon-waning-crescent", + friendly_name: "Moon Phase", + }, + }, + "climate.ground_floor": { + entity_id: "climate.ground_floor", + state: "heat", + attributes: { + hvac_modes: ["auto", "heat", "off"], + min_temp: 7, + max_temp: 35, + preset_modes: [ + "comfort", + "away", + "eco", + "frost_protection", + "external", + "home", + ], + current_temperature: 20.8, + temperature: 21, + preset_mode: "comfort", + icon: "mdi:home-floor-0", + friendly_name: "Ground floor Thermostat", + supported_features: 401, + }, + }, + "climate.first_floor": { + entity_id: "climate.first_floor", + state: "heat", + attributes: { + hvac_modes: ["auto", "heat", "off"], + min_temp: 7, + max_temp: 35, + preset_modes: [ + "comfort", + "away", + "eco", + "frost_protection", + "external", + "home", + ], + current_temperature: 21.7, + temperature: 21, + preset_mode: "comfort", + icon: "mdi:home-floor-1", + friendly_name: "First floor Thermostat", + supported_features: 401, + }, + }, + "cover.study_shutter": { + entity_id: "cover.study_shutter", + state: "open", + attributes: { + current_position: 100, + device_class: "shutter", + friendly_name: "Study shutter", + supported_features: 15, + }, + }, + "light.study_spotlights": { + entity_id: "light.study_spotlights", + state: "off", + attributes: { + supported_color_modes: ["brightness"], + color_mode: null, + brightness: null, + icon: "mdi:ceiling-light-multiple", + friendly_name: "Study spotlights", + supported_features: 32, + }, + }, + "media_player.study_nest_hub": { + entity_id: "media_player.study_nest_hub", + state: "off", + attributes: { + friendly_name: "Study Nest Hub", + supported_features: 152461, + }, + }, + "sensor.standing_desk_height": { + entity_id: "sensor.standing_desk_height", + state: "72", + attributes: { + unit_of_measurement: "cm", + icon: "mdi:tape-measure", + friendly_name: "Standing desk Height", + }, + }, + "light.outdoor_light": { + entity_id: "light.outdoor_light", + state: "on", + attributes: { + supported_color_modes: ["brightness"], + color_mode: null, + brightness: 255, + icon: "mdi:outdoor-lamp", + friendly_name: "Outdoor light", + supported_features: 32, + }, + }, + "light.flood_light": { + entity_id: "light.flood_light", + state: "off", + attributes: { + effect_list: ["None", "candle"], + supported_color_modes: ["brightness"], + effect: null, + color_mode: null, + brightness: null, + mode: "normal", + dynamics: "none", + icon: "mdi:light-flood-down", + friendly_name: "Flood light", + supported_features: 44, + }, + }, + "sensor.outdoor_motion_sensor_temperature": { + entity_id: "sensor.outdoor_motion_sensor_temperature", + state: "10.2", + attributes: { + state_class: "measurement", + unit_of_measurement: "°C", + device_class: "temperature", + friendly_name: "Outdoor motion sensor Temperature", + }, + }, + "binary_sensor.outdoor_motion_sensor_motion": { + entity_id: "binary_sensor.outdoor_motion_sensor_motion", + state: "off", + attributes: { + device_class: "motion", + friendly_name: "Outdoor motion sensor Motion", + }, + }, + "sensor.outdoor_motion_sensor_illuminance": { + entity_id: "sensor.outdoor_motion_sensor_illuminance", + state: "555", + attributes: { + state_class: "measurement", + light_level: 27444, + unit_of_measurement: "lx", + device_class: "illuminance", + friendly_name: "Outdoor motion sensor Illuminance", + }, + }, + "automation.home_assistant_auto_update": { + entity_id: "automation.home_assistant_auto_update", + state: "off", + attributes: { + id: "1700669321947", + last_triggered: "2024-02-29T18:02:05.343139+00:00", + mode: "queued", + current: 0, + max: 50, + icon: "mdi:auto-mode", + friendly_name: "Home Assistant Auto-update", + }, + }, + "update.home_assistant_operating_system_update": { + entity_id: "update.home_assistant_operating_system_update", + state: "off", + attributes: { + auto_update: false, + installed_version: "12.1", + in_progress: false, + latest_version: "12.1", + release_summary: null, + release_url: + "https://github.com/home-assistant/operating-system/commits/dev", + skipped_version: null, + title: "Home Assistant Operating System", + entity_picture: + "https://brands.home-assistant.io/homeassistant/icon.png", + friendly_name: "Home Assistant Operating System Update", + supported_features: 3, + }, + }, + "update.home_assistant_supervisor_update": { + entity_id: "update.home_assistant_supervisor_update", + state: "off", + attributes: { + auto_update: true, + installed_version: "2024.02.2", + in_progress: false, + latest_version: "2024.02.2", + release_summary: null, + release_url: + "https://github.com/home-assistant/supervisor/commits/main", + skipped_version: null, + title: "Home Assistant Supervisor", + entity_picture: "https://brands.home-assistant.io/hassio/icon.png", + friendly_name: "Home Assistant Supervisor Update", + supported_features: 1, + }, + }, + "update.home_assistant_core_update": { + entity_id: "update.home_assistant_supervisor_update", + state: "off", + attributes: { + auto_update: false, + installed_version: "2024.4.0", + in_progress: false, + latest_version: "2024.4.0", + release_summary: null, + release_url: "https://github.com/home-assistant/core/commits/dev", + skipped_version: null, + title: "Home Assistant Core", + entity_picture: + "https://brands.home-assistant.io/homeassistant/icon.png", + friendly_name: "Home Assistant Core Update", + supported_features: 11, + }, + }, + }); diff --git a/demo/src/configs/sections/index.ts b/demo/src/configs/sections/index.ts new file mode 100644 index 0000000000..39bc7419b8 --- /dev/null +++ b/demo/src/configs/sections/index.ts @@ -0,0 +1,12 @@ +import { DemoConfig } from "../types"; +import { demoEntitiesSections } from "./entities"; +import { demoLovelaceSections } from "./lovelace"; + +export const demoSections: DemoConfig = { + authorName: "Home Assistant", + authorUrl: "https://github.com/home-assistant/frontend/", + name: "Home Demo", + lovelace: demoLovelaceSections, + entities: demoEntitiesSections, + theme: () => ({}), +}; diff --git a/demo/src/configs/sections/lovelace.ts b/demo/src/configs/sections/lovelace.ts new file mode 100644 index 0000000000..197a434a2a --- /dev/null +++ b/demo/src/configs/sections/lovelace.ts @@ -0,0 +1,280 @@ +import { DemoConfig } from "../types"; + +export const demoLovelaceSections: DemoConfig["lovelace"] = () => ({ + title: "Home Assistant Demo", + views: [ + { + type: "sections", + title: "Demo", + path: "home", + icon: "mdi:home-assistant", + sections: [ + { + title: "Welcome 👋", + cards: [{ type: "custom:ha-demo-card" }], + }, + { + cards: [ + { + type: "tile", + entity: "cover.living_room_garden_shutter", + name: "Garden", + }, + { + type: "tile", + entity: "cover.living_room_graveyard_shutter", + name: "Rear", + }, + { + type: "tile", + entity: "cover.living_room_left_shutter", + name: "Left", + }, + { + type: "tile", + entity: "cover.living_room_right_shutter", + name: "Right", + }, + { + type: "tile", + entity: "light.floor_lamp", + }, + { + type: "tile", + entity: "light.living_room_spotlights", + name: "Spotlights", + features: [ + { + type: "light-brightness", + }, + ], + }, + { + type: "tile", + entity: "light.bar_lamp", + }, + { + graph: "line", + type: "sensor", + entity: "sensor.living_room_temperature", + detail: 1, + name: "Temperature", + }, + { + type: "tile", + entity: "media_player.living_room_nest_mini", + name: "Nest Mini", + }, + ], + title: "🛋️ Living room ", + }, + { + type: "grid", + cards: [ + { + type: "tile", + entity: "cover.kitchen_shutter", + name: "Shutter", + }, + { + type: "tile", + entity: "light.kitchen_spotlights", + name: "Spotlights", + features: [ + { + type: "light-brightness", + }, + ], + }, + { + type: "tile", + entity: "light.worktop_spotlights", + name: "Worktop", + }, + { + type: "tile", + entity: "binary_sensor.fridge_door", + name: "Fridge", + }, + { + type: "tile", + entity: "media_player.kitchen_nest_audio", + name: "Nest Audio", + }, + ], + title: "👩‍🍳 Kitchen", + }, + { + type: "grid", + cards: [ + { + type: "tile", + entity: "binary_sensor.tesla_wall_connector_vehicle_connected", + name: "EV", + icon: "mdi:car", + }, + { + type: "tile", + entity: "sensor.tesla_wall_connector_session_energy", + name: "EV last charge", + color: "green", + }, + { + type: "tile", + entity: "sensor.electric_meter_power", + color: "deep-orange", + name: "Home power", + }, + { + type: "tile", + entity: "sensor.eletric_meter_voltage", + name: "Voltage", + color: "deep-orange", + }, + { + type: "tile", + entity: "sensor.electricity_maps_grid_fossil_fuel_percentage", + name: "Fossil fuel", + color: "brown", + }, + { + type: "tile", + entity: "sensor.electricity_maps_co2_intensity", + name: "CO2 Intensity", + color: "dark-grey", + }, + ], + title: "⚡️ Energy", + }, + { + type: "grid", + cards: [ + { + type: "tile", + entity: "sun.sun", + }, + { + type: "tile", + entity: "sensor.moon_phase", + color: "indigo", + name: "Moon", + }, + { + features: [ + { + type: "target-temperature", + }, + ], + type: "tile", + entity: "climate.ground_floor", + state_content: ["preset_mode", "current_temperature"], + }, + { + features: [ + { + type: "target-temperature", + }, + ], + type: "tile", + entity: "climate.first_floor", + state_content: ["preset_mode", "current_temperature"], + }, + ], + title: "🌤️ Climate", + }, + { + type: "grid", + cards: [ + { + type: "tile", + entity: "cover.study_shutter", + name: "Shutter", + }, + { + type: "tile", + entity: "light.study_spotlights", + name: "Spotlights", + }, + { + type: "tile", + entity: "media_player.study_nest_hub", + name: "Nest Hub", + }, + { + type: "tile", + entity: "sensor.standing_desk_height", + name: "Desk", + color: "brown", + icon: "mdi:desk", + }, + ], + title: "🧑‍💻 Study", + }, + { + type: "grid", + cards: [ + { + type: "tile", + entity: "light.outdoor_light", + name: "Door light", + }, + { + type: "tile", + entity: "light.flood_light", + }, + { + graph: "line", + type: "sensor", + entity: "sensor.outdoor_motion_sensor_temperature", + detail: 1, + name: "Temperature", + }, + { + type: "tile", + entity: "binary_sensor.outdoor_motion_sensor_motion", + name: "Motion", + color: "blue", + }, + { + type: "tile", + entity: "sensor.outdoor_motion_sensor_illuminance", + color: "amber", + name: "Illuminance", + }, + ], + title: "🌳 Outdoor", + }, + { + type: "grid", + cards: [ + { + type: "tile", + entity: "automation.home_assistant_auto_update", + name: "Auto-update", + color: "green", + }, + { + type: "tile", + entity: "update.home_assistant_operating_system_update", + name: "OS", + icon: "mdi:home-assistant", + }, + { + type: "tile", + entity: "update.home_assistant_supervisor_update", + icon: "mdi:home-assistant", + name: "Supervisor", + }, + { + type: "tile", + entity: "update.home_assistant_core_update", + name: "Core", + icon: "mdi:home-assistant", + }, + ], + title: "🎉 Updates", + }, + ], + }, + ], +}); diff --git a/src/panels/lovelace/sections/hui-grid-section.ts b/src/panels/lovelace/sections/hui-grid-section.ts index b63e9fac8f..72fc0b13df 100644 --- a/src/panels/lovelace/sections/hui-grid-section.ts +++ b/src/panels/lovelace/sections/hui-grid-section.ts @@ -96,6 +96,7 @@ export class GridSection extends LitElement implements LovelaceSectionElement { (_cardConfig, idx) => { const card = this.cards![idx]; (card as any).editMode = editMode; + (card as any).lovelace = this.lovelace; const size = card && (card as any).getGridSize?.(); return html`