Add demo (#2502)
* Add demo * Fix stuff * Lint * Typescript and demo card * More fixes * Allow switching through configs * Lint * Lint2 * Add two demo configs * Lint * Lint
This commit is contained in:
@@ -3,9 +3,9 @@ import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
import JsYaml from "js-yaml";
|
||||
|
||||
import HomeAssistant from "../data/hass";
|
||||
import { demoConfig } from "../data/demo_config";
|
||||
import { demoServices } from "../data/demo_services";
|
||||
import demoResources from "../data/demo_resources";
|
||||
import { demoConfig } from "../../../src/fake_data/demo_config";
|
||||
import { demoServices } from "../../../src/fake_data/demo_services";
|
||||
import demoResources from "../../../src/fake_data/demo_resources";
|
||||
import demoStates from "../data/demo_states";
|
||||
import { createCardElement } from "../../../src/panels/lovelace/common/create-card-element";
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
export const demoConfig = {
|
||||
elevation: 300,
|
||||
latitude: 51.5287352,
|
||||
longitude: -0.381773,
|
||||
unit_system: {
|
||||
length: "km",
|
||||
mass: "kg",
|
||||
temperature: "°C",
|
||||
volume: "L",
|
||||
},
|
||||
};
|
||||
@@ -1,264 +0,0 @@
|
||||
export default {
|
||||
en: {
|
||||
"state.default.off": "Off",
|
||||
"state.default.on": "On",
|
||||
"state.default.unknown": "Unknown",
|
||||
"state.default.unavailable": "Unavailable",
|
||||
"state.alarm_control_panel.armed": "Armed",
|
||||
"state.alarm_control_panel.disarmed": "Disarmed",
|
||||
"state.alarm_control_panel.armed_home": "Armed home",
|
||||
"state.alarm_control_panel.armed_away": "Armed away",
|
||||
"state.alarm_control_panel.armed_night": "Armed night",
|
||||
"state.alarm_control_panel.armed_custom_bypass": "Armed custom bypass",
|
||||
"state.alarm_control_panel.pending": "Pending",
|
||||
"state.alarm_control_panel.arming": "Arming",
|
||||
"state.alarm_control_panel.disarming": "Disarming",
|
||||
"state.alarm_control_panel.triggered": "Triggered",
|
||||
"state.automation.off": "Off",
|
||||
"state.automation.on": "On",
|
||||
"state.binary_sensor.default.off": "Off",
|
||||
"state.binary_sensor.default.on": "On",
|
||||
"state.binary_sensor.battery.off": "Normal",
|
||||
"state.binary_sensor.battery.on": "Low",
|
||||
"state.binary_sensor.cold.off": "Normal",
|
||||
"state.binary_sensor.cold.on": "Cold",
|
||||
"state.binary_sensor.connectivity.off": "Disconnected",
|
||||
"state.binary_sensor.connectivity.on": "Connected",
|
||||
"state.binary_sensor.door.off": "Closed",
|
||||
"state.binary_sensor.door.on": "Open",
|
||||
"state.binary_sensor.garage_door.off": "Closed",
|
||||
"state.binary_sensor.garage_door.on": "Open",
|
||||
"state.binary_sensor.gas.off": "Clear",
|
||||
"state.binary_sensor.gas.on": "Detected",
|
||||
"state.binary_sensor.heat.off": "Normal",
|
||||
"state.binary_sensor.heat.on": "Hot",
|
||||
"state.binary_sensor.lock.off": "Locked",
|
||||
"state.binary_sensor.lock.on": "Unlocked",
|
||||
"state.binary_sensor.moisture.off": "Dry",
|
||||
"state.binary_sensor.moisture.on": "Wet",
|
||||
"state.binary_sensor.motion.off": "Clear",
|
||||
"state.binary_sensor.motion.on": "Detected",
|
||||
"state.binary_sensor.occupancy.off": "Clear",
|
||||
"state.binary_sensor.occupancy.on": "Detected",
|
||||
"state.binary_sensor.opening.off": "Closed",
|
||||
"state.binary_sensor.opening.on": "Open",
|
||||
"state.binary_sensor.presence.off": "Away",
|
||||
"state.binary_sensor.presence.on": "Home",
|
||||
"state.binary_sensor.problem.off": "OK",
|
||||
"state.binary_sensor.problem.on": "Problem",
|
||||
"state.binary_sensor.safety.off": "Safe",
|
||||
"state.binary_sensor.safety.on": "Unsafe",
|
||||
"state.binary_sensor.smoke.off": "Clear",
|
||||
"state.binary_sensor.smoke.on": "Detected",
|
||||
"state.binary_sensor.sound.off": "Clear",
|
||||
"state.binary_sensor.sound.on": "Detected",
|
||||
"state.binary_sensor.vibration.off": "Clear",
|
||||
"state.binary_sensor.vibration.on": "Detected",
|
||||
"state.binary_sensor.window.off": "Closed",
|
||||
"state.binary_sensor.window.on": "Open",
|
||||
"state.calendar.off": "Off",
|
||||
"state.calendar.on": "On",
|
||||
"state.camera.recording": "Recording",
|
||||
"state.camera.streaming": "Streaming",
|
||||
"state.camera.idle": "Idle",
|
||||
"state.climate.off": "Off",
|
||||
"state.climate.on": "On",
|
||||
"state.climate.heat": "Heat",
|
||||
"state.climate.cool": "Cool",
|
||||
"state.climate.idle": "Idle",
|
||||
"state.climate.auto": "Auto",
|
||||
"state.climate.dry": "Dry",
|
||||
"state.climate.fan_only": "Fan only",
|
||||
"state.climate.eco": "Eco",
|
||||
"state.climate.electric": "Electric",
|
||||
"state.climate.performance": "Performance",
|
||||
"state.climate.high_demand": "High demand",
|
||||
"state.climate.heat_pump": "Heat pump",
|
||||
"state.climate.gas": "Gas",
|
||||
"state.configurator.configure": "Configure",
|
||||
"state.configurator.configured": "Configured",
|
||||
"state.cover.open": "Open",
|
||||
"state.cover.opening": "Opening",
|
||||
"state.cover.closed": "Closed",
|
||||
"state.cover.closing": "Closing",
|
||||
"state.cover.stopped": "Stopped",
|
||||
"state.device_tracker.home": "Home",
|
||||
"state.device_tracker.not_home": "Away",
|
||||
"state.fan.off": "Off",
|
||||
"state.fan.on": "On",
|
||||
"state.group.off": "Off",
|
||||
"state.group.on": "On",
|
||||
"state.group.home": "Home",
|
||||
"state.group.not_home": "Away",
|
||||
"state.group.open": "Open",
|
||||
"state.group.opening": "Opening",
|
||||
"state.group.closed": "Closed",
|
||||
"state.group.closing": "Closing",
|
||||
"state.group.stopped": "Stopped",
|
||||
"state.group.locked": "Locked",
|
||||
"state.group.unlocked": "Unlocked",
|
||||
"state.group.ok": "OK",
|
||||
"state.group.problem": "Problem",
|
||||
"state.input_boolean.off": "Off",
|
||||
"state.input_boolean.on": "On",
|
||||
"state.light.off": "Off",
|
||||
"state.light.on": "On",
|
||||
"state.lock.locked": "Locked",
|
||||
"state.lock.unlocked": "Unlocked",
|
||||
"state.media_player.off": "Off",
|
||||
"state.media_player.on": "On",
|
||||
"state.media_player.playing": "Playing",
|
||||
"state.media_player.paused": "Paused",
|
||||
"state.media_player.idle": "Idle",
|
||||
"state.media_player.standby": "Standby",
|
||||
"state.plant.ok": "OK",
|
||||
"state.plant.problem": "Problem",
|
||||
"state.remote.off": "Off",
|
||||
"state.remote.on": "On",
|
||||
"state.scene.scening": "Scening",
|
||||
"state.script.off": "Off",
|
||||
"state.script.on": "On",
|
||||
"state.sensor.off": "Off",
|
||||
"state.sensor.on": "On",
|
||||
"state.sun.above_horizon": "Above horizon",
|
||||
"state.sun.below_horizon": "Below horizon",
|
||||
"state.switch.off": "Off",
|
||||
"state.switch.on": "On",
|
||||
"state.weather.clear-night": "Clear, night",
|
||||
"state.weather.cloudy": "Cloudy",
|
||||
"state.weather.fog": "Fog",
|
||||
"state.weather.hail": "Hail",
|
||||
"state.weather.lightning": "Lightning",
|
||||
"state.weather.lightning-rainy": "Lightning, rainy",
|
||||
"state.weather.partlycloudy": "Partly cloudy",
|
||||
"state.weather.pouring": "Pouring",
|
||||
"state.weather.rainy": "Rainy",
|
||||
"state.weather.snowy": "Snowy",
|
||||
"state.weather.snowy-rainy": "Snowy, rainy",
|
||||
"state.weather.sunny": "Sunny",
|
||||
"state.weather.windy": "Windy",
|
||||
"state.weather.windy-variant": "Windy",
|
||||
"state.zwave.default.initializing": "Initializing",
|
||||
"state.zwave.default.dead": "Dead",
|
||||
"state.zwave.default.sleeping": "Sleeping",
|
||||
"state.zwave.default.ready": "Ready",
|
||||
"state.zwave.query_stage.initializing": "Initializing ({query_stage})",
|
||||
"state.zwave.query_stage.dead": "Dead ({query_stage})",
|
||||
"state_badge.default.unknown": "Unk",
|
||||
"state_badge.default.unavailable": "Unavai",
|
||||
"state_badge.alarm_control_panel.armed": "Armed",
|
||||
"state_badge.alarm_control_panel.disarmed": "Disarm",
|
||||
"state_badge.alarm_control_panel.armed_home": "Armed",
|
||||
"state_badge.alarm_control_panel.armed_away": "Armed",
|
||||
"state_badge.alarm_control_panel.armed_night": "Armed",
|
||||
"state_badge.alarm_control_panel.armed_custom_bypass": "Armed",
|
||||
"state_badge.alarm_control_panel.pending": "Pend",
|
||||
"state_badge.alarm_control_panel.arming": "Arming",
|
||||
"state_badge.alarm_control_panel.disarming": "Disarm",
|
||||
"state_badge.alarm_control_panel.triggered": "Trig",
|
||||
"state_badge.device_tracker.home": "Home",
|
||||
"state_badge.device_tracker.not_home": "Away",
|
||||
"ui.card.alarm_control_panel.code": "Code",
|
||||
"ui.card.alarm_control_panel.clear_code": "Clear",
|
||||
"ui.card.alarm_control_panel.disarm": "Disarm",
|
||||
"ui.card.alarm_control_panel.arm_home": "Arm home",
|
||||
"ui.card.alarm_control_panel.arm_away": "Arm away",
|
||||
"ui.card.automation.last_triggered": "Last triggered",
|
||||
"ui.card.automation.trigger": "Trigger",
|
||||
"ui.card.camera.not_available": "Image not available",
|
||||
"ui.card.climate.currently": "Currently",
|
||||
"ui.card.climate.on_off": "On / off",
|
||||
"ui.card.climate.target_temperature": "Target temperature",
|
||||
"ui.card.climate.target_humidity": "Target humidity",
|
||||
"ui.card.climate.operation": "Operation",
|
||||
"ui.card.climate.fan_mode": "Fan mode",
|
||||
"ui.card.climate.swing_mode": "Swing mode",
|
||||
"ui.card.climate.away_mode": "Away mode",
|
||||
"ui.card.climate.aux_heat": "Aux heat",
|
||||
"ui.card.cover.position": "Position",
|
||||
"ui.card.cover.tilt_position": "Tilt position",
|
||||
"ui.card.fan.speed": "Speed",
|
||||
"ui.card.fan.oscillate": "Oscillate",
|
||||
"ui.card.fan.direction": "Direction",
|
||||
"ui.card.light.brightness": "Brightness",
|
||||
"ui.card.light.color_temperature": "Color temperature",
|
||||
"ui.card.light.white_value": "White value",
|
||||
"ui.card.light.effect": "Effect",
|
||||
"ui.card.lock.code": "Code",
|
||||
"ui.card.lock.lock": "Lock",
|
||||
"ui.card.lock.unlock": "Unlock",
|
||||
"ui.card.media_player.source": "Source",
|
||||
"ui.card.media_player.sound_mode": "Sound mode",
|
||||
"ui.card.media_player.text_to_speak": "Text to speak",
|
||||
"ui.card.persistent_notification.dismiss": "Dismiss",
|
||||
"ui.card.scene.activate": "Activate",
|
||||
"ui.card.script.execute": "Execute",
|
||||
"ui.card.weather.attributes.air_pressure": "Air pressure",
|
||||
"ui.card.weather.attributes.humidity": "Humidity",
|
||||
"ui.card.weather.attributes.temperature": "Temperature",
|
||||
"ui.card.weather.attributes.visibility": "Visibility",
|
||||
"ui.card.weather.attributes.wind_speed": "Wind speed",
|
||||
"ui.card.weather.cardinal_direction.e": "E",
|
||||
"ui.card.weather.cardinal_direction.ene": "ENE",
|
||||
"ui.card.weather.cardinal_direction.ese": "ESE",
|
||||
"ui.card.weather.cardinal_direction.n": "N",
|
||||
"ui.card.weather.cardinal_direction.ne": "NE",
|
||||
"ui.card.weather.cardinal_direction.nne": "NNE",
|
||||
"ui.card.weather.cardinal_direction.nw": "NW",
|
||||
"ui.card.weather.cardinal_direction.nnw": "NNW",
|
||||
"ui.card.weather.cardinal_direction.s": "S",
|
||||
"ui.card.weather.cardinal_direction.se": "SE",
|
||||
"ui.card.weather.cardinal_direction.sse": "SSE",
|
||||
"ui.card.weather.cardinal_direction.ssw": "SSW",
|
||||
"ui.card.weather.cardinal_direction.sw": "SW",
|
||||
"ui.card.weather.cardinal_direction.w": "W",
|
||||
"ui.card.weather.cardinal_direction.wnw": "WNW",
|
||||
"ui.card.weather.cardinal_direction.wsw": "WSW",
|
||||
"ui.card.weather.forecast": "Forecast",
|
||||
"ui.common.loading": "Loading",
|
||||
"ui.common.cancel": "Cancel",
|
||||
"ui.components.entity.entity-picker.entity": "Entity",
|
||||
"ui.components.relative_time.past": "{time} ago",
|
||||
"ui.components.relative_time.future": "In {time}",
|
||||
"ui.components.relative_time.never": "Never",
|
||||
"ui.components.relative_time.duration.second":
|
||||
"{count} {count, plural,\n one {second}\n other {seconds}\n}",
|
||||
"ui.components.relative_time.duration.minute":
|
||||
"{count} {count, plural,\n one {minute}\n other {minutes}\n}",
|
||||
"ui.components.relative_time.duration.hour":
|
||||
"{count} {count, plural,\n one {hour}\n other {hours}\n}",
|
||||
"ui.components.relative_time.duration.day":
|
||||
"{count} {count, plural,\n one {day}\n other {days}\n}",
|
||||
"ui.components.relative_time.duration.week":
|
||||
"{count} {count, plural,\n one {week}\n other {weeks}\n}",
|
||||
"ui.components.history_charts.loading_history": "Loading state history...",
|
||||
"ui.components.history_charts.no_history_found": "No state history found.",
|
||||
"ui.components.service-picker.service": "Service",
|
||||
"ui.dialogs.more_info_settings.save": "Save",
|
||||
"ui.dialogs.more_info_settings.name": "Name",
|
||||
"ui.duration.second":
|
||||
"{count} {count, plural,\n one {second}\n other {seconds}\n}",
|
||||
"ui.duration.minute":
|
||||
"{count} {count, plural,\n one {minute}\n other {minutes}\n}",
|
||||
"ui.duration.hour":
|
||||
"{count} {count, plural,\n one {hour}\n other {hours}\n}",
|
||||
"ui.duration.day":
|
||||
"{count} {count, plural,\n one {day}\n other {days}\n}",
|
||||
"ui.duration.week":
|
||||
"{count} {count, plural,\n one {week}\n other {weeks}\n}",
|
||||
"ui.login-form.password": "Password",
|
||||
"ui.login-form.remember": "Remember",
|
||||
"ui.login-form.log_in": "Log in",
|
||||
"ui.notification_toast.entity_turned_on": "Turned on {entity}.",
|
||||
"ui.notification_toast.entity_turned_off": "Turned off {entity}.",
|
||||
"ui.notification_toast.service_called": "Service {service} called.",
|
||||
"ui.notification_toast.service_call_failed":
|
||||
"Failed to call service {service}.",
|
||||
"ui.notification_toast.connection_lost": "Connection lost. Reconnecting…",
|
||||
"ui.sidebar.developer_tools": "Developer tools",
|
||||
"ui.sidebar.log_out": "Log out",
|
||||
"attribute.weather.humidity": "Humidity",
|
||||
"attribute.weather.visibility": "Visibility",
|
||||
"attribute.weather.wind_speed": "Wind speed",
|
||||
},
|
||||
};
|
||||
@@ -1,96 +0,0 @@
|
||||
export const demoServices = {
|
||||
configurator: ["configure"],
|
||||
tts: ["demo_say", "clear_cache"],
|
||||
cover: [
|
||||
"open_cover",
|
||||
"close_cover",
|
||||
"open_cover_tilt",
|
||||
"close_cover_tilt",
|
||||
"set_cover_tilt_position",
|
||||
"set_cover_position",
|
||||
"stop_cover_tilt",
|
||||
"stop_cover",
|
||||
],
|
||||
group: ["set", "reload", "remove", "set_visibility"],
|
||||
alarm_control_panel: [
|
||||
"alarm_arm_night",
|
||||
"alarm_disarm",
|
||||
"alarm_trigger",
|
||||
"alarm_arm_home",
|
||||
"alarm_arm_away",
|
||||
"alarm_arm_custom_bypass",
|
||||
],
|
||||
conversation: ["process"],
|
||||
notify: ["demo_test_target_name", "notify"],
|
||||
lock: ["open", "lock", "unlock"],
|
||||
input_select: [
|
||||
"select_previous",
|
||||
"set_options",
|
||||
"select_next",
|
||||
"select_option",
|
||||
],
|
||||
recorder: ["purge"],
|
||||
persistent_notification: ["create", "dismiss"],
|
||||
timer: ["pause", "cancel", "finish", "start"],
|
||||
input_boolean: ["turn_off", "toggle", "turn_on"],
|
||||
fan: [
|
||||
"set_speed",
|
||||
"turn_on",
|
||||
"turn_off",
|
||||
"set_direction",
|
||||
"oscillate",
|
||||
"toggle",
|
||||
],
|
||||
climate: [
|
||||
"set_humidity",
|
||||
"set_operation_mode",
|
||||
"set_aux_heat",
|
||||
"turn_on",
|
||||
"set_hold_mode",
|
||||
"set_away_mode",
|
||||
"turn_off",
|
||||
"set_fan_mode",
|
||||
"set_temperature",
|
||||
"set_swing_mode",
|
||||
],
|
||||
switch: ["turn_off", "toggle", "turn_on"],
|
||||
script: ["turn_off", "demo", "reload", "toggle", "turn_on"],
|
||||
scene: ["turn_on"],
|
||||
system_log: ["clear", "write"],
|
||||
camera: ["disable_motion_detection", "enable_motion_detection", "snapshot"],
|
||||
image_processing: ["scan"],
|
||||
media_player: [
|
||||
"media_previous_track",
|
||||
"clear_playlist",
|
||||
"shuffle_set",
|
||||
"media_seek",
|
||||
"turn_on",
|
||||
"media_play_pause",
|
||||
"media_next_track",
|
||||
"media_pause",
|
||||
"volume_down",
|
||||
"volume_set",
|
||||
"media_stop",
|
||||
"toggle",
|
||||
"media_play",
|
||||
"play_media",
|
||||
"volume_mute",
|
||||
"turn_off",
|
||||
"select_sound_mode",
|
||||
"select_source",
|
||||
"volume_up",
|
||||
],
|
||||
input_number: ["set_value", "increment", "decrement"],
|
||||
device_tracker: ["see"],
|
||||
homeassistant: [
|
||||
"stop",
|
||||
"check_config",
|
||||
"reload_core_config",
|
||||
"turn_on",
|
||||
"turn_off",
|
||||
"restart",
|
||||
"toggle",
|
||||
],
|
||||
light: ["turn_off", "toggle", "turn_on"],
|
||||
input_text: ["set_value"],
|
||||
};
|
||||
@@ -1,143 +0,0 @@
|
||||
const now = () => new Date().toISOString();
|
||||
const randomTime = () =>
|
||||
new Date(new Date().getTime() - Math.random() * 80 * 60 * 1000).toISOString();
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
export class Entity {
|
||||
constructor(domain, objectId, state, baseAttributes) {
|
||||
this.domain = domain;
|
||||
this.objectId = objectId;
|
||||
this.entityId = `${domain}.${objectId}`;
|
||||
this.lastChanged = randomTime();
|
||||
this.lastUpdated = randomTime();
|
||||
this.state = state;
|
||||
// These are the attributes that we always write to the state machine
|
||||
this.baseAttributes = baseAttributes;
|
||||
this.attributes = baseAttributes;
|
||||
}
|
||||
|
||||
async handleService(domain, service, data) {
|
||||
console.log(
|
||||
`Unmocked service for ${this.entityId}: ${domain}/${service}`,
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
update(state, attributes = {}) {
|
||||
this.state = state;
|
||||
this.lastUpdated = now();
|
||||
this.lastChanged =
|
||||
state === this.state ? this.lastChanged : this.lastUpdated;
|
||||
this.attributes = Object.assign({}, this.baseAttributes, attributes);
|
||||
|
||||
console.log("update", this.entityId, this);
|
||||
|
||||
this.hass.updateStates({
|
||||
[this.entityId]: this.toState(),
|
||||
});
|
||||
}
|
||||
|
||||
toState() {
|
||||
return {
|
||||
entity_id: this.entityId,
|
||||
state: this.state,
|
||||
attributes: this.attributes,
|
||||
last_changed: this.lastChanged,
|
||||
last_updated: this.lastUpdated,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export class LightEntity extends Entity {
|
||||
async handleService(domain, service, data) {
|
||||
if (!["homeassistant", this.domain].includes(domain)) return;
|
||||
|
||||
if (service === "turn_on") {
|
||||
// eslint-disable-next-line
|
||||
let { brightness, hs_color, brightness_pct } = data;
|
||||
// eslint-disable-next-line
|
||||
brightness = (255 * brightness_pct) / 100;
|
||||
this.update(
|
||||
"on",
|
||||
Object.assign(this.attributes, {
|
||||
brightness,
|
||||
hs_color,
|
||||
})
|
||||
);
|
||||
} else if (service === "turn_off") {
|
||||
this.update("off");
|
||||
} else if (service === "toggle") {
|
||||
if (this.state === "on") {
|
||||
this.handleService(domain, "turn_off", data);
|
||||
} else {
|
||||
this.handleService(domain, "turn_on", data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class LockEntity extends Entity {
|
||||
async handleService(domain, service, data) {
|
||||
if (domain !== this.domain) return;
|
||||
|
||||
if (service === "lock") {
|
||||
this.update("locked");
|
||||
} else if (service === "unlock") {
|
||||
this.update("unlocked");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class CoverEntity extends Entity {
|
||||
async handleService(domain, service, data) {
|
||||
if (domain !== this.domain) return;
|
||||
|
||||
if (service === "open_cover") {
|
||||
this.update("open");
|
||||
} else if (service === "close_cover") {
|
||||
this.update("closing");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class ClimateEntity extends Entity {
|
||||
async handleService(domain, service, data) {
|
||||
if (domain !== this.domain) return;
|
||||
|
||||
if (service === "set_operation_mode") {
|
||||
this.update(
|
||||
data.operation_mode === "heat" ? "heat" : data.operation_mode,
|
||||
Object.assign(this.attributes, {
|
||||
operation_mode: data.operation_mode,
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class GroupEntity extends Entity {
|
||||
async handleService(domain, service, data) {
|
||||
if (!["homeassistant", this.domain].includes(domain)) return;
|
||||
|
||||
await Promise.all(
|
||||
this.attributes.entity_id.map((ent) => {
|
||||
const entity = this.hass.mockEntities[ent];
|
||||
return entity.handleService(entity.domain, service, data);
|
||||
})
|
||||
);
|
||||
|
||||
this.update(service === "turn_on" ? "on" : "off");
|
||||
}
|
||||
}
|
||||
|
||||
const TYPES = {
|
||||
climate: ClimateEntity,
|
||||
light: LightEntity,
|
||||
lock: LockEntity,
|
||||
cover: CoverEntity,
|
||||
group: GroupEntity,
|
||||
};
|
||||
|
||||
export default (domain, objectId, state, baseAttributes = {}) =>
|
||||
new (TYPES[domain] || Entity)(domain, objectId, state, baseAttributes);
|
||||
@@ -1,112 +0,0 @@
|
||||
import { fireEvent } from "../../../src/common/dom/fire_event";
|
||||
|
||||
import { demoConfig } from "./demo_config";
|
||||
import { demoServices } from "./demo_services";
|
||||
import demoResources from "./demo_resources";
|
||||
|
||||
const ensureArray = (val) => (Array.isArray(val) ? val : [val]);
|
||||
|
||||
export default (elements, { initialStates = {} } = {}) => {
|
||||
elements = ensureArray(elements);
|
||||
|
||||
const wsCommands = {};
|
||||
const restResponses = {};
|
||||
let hass;
|
||||
const entities = {};
|
||||
|
||||
function updateHass(obj) {
|
||||
hass = Object.assign({}, hass, obj);
|
||||
elements.forEach((el) => {
|
||||
el.hass = hass;
|
||||
});
|
||||
}
|
||||
|
||||
updateHass({
|
||||
// Home Assistant properties
|
||||
config: demoConfig,
|
||||
services: demoServices,
|
||||
language: "en",
|
||||
resources: demoResources,
|
||||
states: initialStates,
|
||||
themes: {},
|
||||
connection: {
|
||||
subscribeEvents: async (callback, event) => {
|
||||
console.log("subscribeEvents", event);
|
||||
return () => console.log("unsubscribeEvents", event);
|
||||
},
|
||||
},
|
||||
|
||||
// Mock properties
|
||||
mockEntities: entities,
|
||||
|
||||
// Home Assistant functions
|
||||
async callService(domain, service, data) {
|
||||
fireEvent(elements[0], "show-notification", {
|
||||
message: `Called service ${domain}/${service}`,
|
||||
});
|
||||
if (data.entity_id) {
|
||||
await Promise.all(
|
||||
ensureArray(data.entity_id).map((ent) =>
|
||||
entities[ent].handleService(domain, service, data)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
console.log("unmocked callService", domain, service, data);
|
||||
}
|
||||
},
|
||||
|
||||
async callWS(msg) {
|
||||
const callback = wsCommands[msg.type];
|
||||
return callback
|
||||
? callback(msg)
|
||||
: Promise.reject({
|
||||
code: "command_not_mocked",
|
||||
message: "This command is not implemented in the gallery.",
|
||||
});
|
||||
},
|
||||
|
||||
async sendWS(msg) {
|
||||
const callback = wsCommands[msg.type];
|
||||
|
||||
if (callback) {
|
||||
callback(msg);
|
||||
} else {
|
||||
console.error(`Unknown command: ${msg.type}`);
|
||||
}
|
||||
console.log("sendWS", msg);
|
||||
},
|
||||
|
||||
async callApi(method, path, parameters) {
|
||||
const callback = restResponses[path];
|
||||
|
||||
return callback
|
||||
? callback(method, path, parameters)
|
||||
: Promise.reject(`Mock for {path} is not implemented`);
|
||||
},
|
||||
|
||||
// Mock functions
|
||||
updateHass,
|
||||
updateStates(newStates) {
|
||||
updateHass({
|
||||
states: Object.assign({}, hass.states, newStates),
|
||||
});
|
||||
},
|
||||
addEntities(newEntities) {
|
||||
const states = {};
|
||||
ensureArray(newEntities).forEach((ent) => {
|
||||
ent.hass = hass;
|
||||
entities[ent.entityId] = ent;
|
||||
states[ent.entityId] = ent.toState();
|
||||
});
|
||||
this.updateStates(states);
|
||||
},
|
||||
mockWS(type, callback) {
|
||||
wsCommands[type] = callback;
|
||||
},
|
||||
mockAPI(path, callback) {
|
||||
restResponses[path] = callback;
|
||||
},
|
||||
});
|
||||
|
||||
return hass;
|
||||
};
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const CONFIGS = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { html } from "@polymer/polymer/lib/utils/html-tag";
|
||||
import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
import "../components/demo-cards";
|
||||
|
||||
const ENTITIES = [
|
||||
|
||||
@@ -4,8 +4,8 @@ import { PolymerElement } from "@polymer/polymer/polymer-element";
|
||||
import "../../../src/dialogs/more-info/controls/more-info-content";
|
||||
import "../../../src/components/ha-card";
|
||||
|
||||
import getEntity from "../data/entity";
|
||||
import provideHass from "../data/provide_hass";
|
||||
import { getEntity } from "../../../src/fake_data/entity";
|
||||
import { provideHass } from "../../../src/fake_data/provide_hass";
|
||||
|
||||
import "../components/demo-more-infos";
|
||||
import { SUPPORT_BRIGHTNESS } from "../../../src/data/light";
|
||||
|
||||
Reference in New Issue
Block a user