From e4b2ec1710da8d6e134f9846813833e6d7ce2929 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 29 Jan 2017 23:19:35 -0800 Subject: [PATCH] Add demo data back --- demo_data/bootstrap_data.js | 13 ++ demo_data/config_data.js | 18 +++ demo_data/event_data.js | 18 +++ demo_data/expose_window.js | 5 + demo_data/logbook_data.js | 93 +++++++++++ demo_data/panel_data.js | 48 ++++++ demo_data/service_data.js | 37 +++++ demo_data/state_data.js | 279 ++++++++++++++++++++++++++++++++ demo_data/state_history_data.js | 257 +++++++++++++++++++++++++++++ rollup/demo.js | 2 +- 10 files changed, 769 insertions(+), 1 deletion(-) create mode 100755 demo_data/bootstrap_data.js create mode 100755 demo_data/config_data.js create mode 100755 demo_data/event_data.js create mode 100755 demo_data/expose_window.js create mode 100755 demo_data/logbook_data.js create mode 100755 demo_data/panel_data.js create mode 100755 demo_data/service_data.js create mode 100755 demo_data/state_data.js create mode 100755 demo_data/state_history_data.js diff --git a/demo_data/bootstrap_data.js b/demo_data/bootstrap_data.js new file mode 100755 index 0000000000..1f7809610f --- /dev/null +++ b/demo_data/bootstrap_data.js @@ -0,0 +1,13 @@ +import config from './config_data'; +import events from './event_data'; +import services from './service_data'; +import states from './state_data'; +import panels from './panel_data'; + +export default { + config, + events, + panels, + services, + states, +}; diff --git a/demo_data/config_data.js b/demo_data/config_data.js new file mode 100755 index 0000000000..eb92502564 --- /dev/null +++ b/demo_data/config_data.js @@ -0,0 +1,18 @@ +export default { + components: [ + 'configurator', + 'http', + 'api', + 'frontend', + 'history', + 'conversation', + 'logbook', + 'introduction', + ], + latitude: 32.87336, + location_name: 'Home', + longitude: -117.22743, + temperature_unit: '\u00b0F', + time_zone: 'America/Los_Angeles', + version: '0.26', +}; diff --git a/demo_data/event_data.js b/demo_data/event_data.js new file mode 100755 index 0000000000..3642f22943 --- /dev/null +++ b/demo_data/event_data.js @@ -0,0 +1,18 @@ +export default [ + { + event: 'call_service', + listener_count: 1, + }, + { + event: 'time_changed', + listener_count: 1, + }, + { + event: 'state_changed', + listener_count: 3, + }, + { + event: 'homeassistant_stop', + listener_count: 2, + }, +]; diff --git a/demo_data/expose_window.js b/demo_data/expose_window.js new file mode 100755 index 0000000000..f98a2035b1 --- /dev/null +++ b/demo_data/expose_window.js @@ -0,0 +1,5 @@ +import bootstrap from './bootstrap_data'; +import logbook from './logbook_data'; +import stateHistory from './state_history_data'; + +window.hassDemoData = { bootstrap, logbook, stateHistory }; diff --git a/demo_data/logbook_data.js b/demo_data/logbook_data.js new file mode 100755 index 0000000000..1e5772fb24 --- /dev/null +++ b/demo_data/logbook_data.js @@ -0,0 +1,93 @@ +export default [ + { + domain: 'sun', + entity_id: 'sun.sun', + message: 'has risen', + name: 'sun', + when: '2015-04-24T06:08:47.000Z', + }, + { + domain: 'device_tracker', + entity_id: 'device_tracker.paulus', + message: 'left home', + name: 'Paulus', + when: '2015-04-24T08:54:47.000Z', + }, + { + domain: 'device_tracker', + entity_id: 'device_tracker.anne_therese', + message: 'left home', + name: 'Anne Therese', + when: '2015-04-24T09:08:47.000Z', + }, + { + domain: 'group', + entity_id: 'group.all_devices', + message: 'left home', + name: 'All devices', + when: '2015-04-24T09:08:47.000Z', + }, + { + domain: 'thermostat', + entity_id: 'thermostat.nest', + message: 'changed to 17 \u00b0C', + name: 'Nest', + when: '2015-04-24T09:08:47.000Z', + }, + { + domain: 'thermostat', + entity_id: 'thermostat.nest', + message: 'changed to 21 \u00b0C', + name: 'Nest', + when: '2015-04-24T16:00:47.000Z', + }, + { + domain: 'device_tracker', + entity_id: 'device_tracker.anne_therese', + message: 'came home', + name: 'Anne Therese', + when: '2015-04-24T16:24:47.000Z', + }, + { + domain: 'group', + entity_id: 'group.all_devices', + message: 'came home', + name: 'All devices', + when: '2015-04-24T16:24:47.000Z', + }, + { + domain: 'light', + entity_id: 'light.bowl', + message: 'turned on', + name: 'Bowl', + when: '2015-04-24T18:01:47.000Z', + }, + { + domain: 'light', + entity_id: 'light.ceiling', + message: 'turned on', + name: 'Ceiling', + when: '2015-04-24T18:16:47.000Z', + }, + { + domain: 'light', + entity_id: 'light.tv_back_light', + message: 'turned on', + name: 'TV Back Light', + when: '2015-04-24T18:31:47.000Z', + }, + { + domain: 'sun', + entity_id: 'sun.sun', + message: 'has set', + name: 'sun', + when: '2015-04-24T18:46:47.000Z', + }, + { + domain: 'media_player', + entity_id: 'media_player.living_room', + message: 'changed to Plex', + name: 'Media Player', + when: '2015-04-24T19:12:47.000Z', + }, +]; diff --git a/demo_data/panel_data.js b/demo_data/panel_data.js new file mode 100755 index 0000000000..1d0e06e22d --- /dev/null +++ b/demo_data/panel_data.js @@ -0,0 +1,48 @@ +export default { + 'dev-event': { + component_name: 'dev-event', + url: '/demo/panels/ha-panel-dev-event.html', + url_name: 'dev-event', + }, + 'dev-info': { + component_name: 'dev-info', + url: '/demo/panels/ha-panel-dev-info.html', + url_name: 'dev-info', + }, + 'dev-service': { + component_name: 'dev-service', + url: '/demo/panels/ha-panel-dev-service.html', + url_name: 'dev-service', + }, + 'dev-state': { + component_name: 'dev-state', + url: '/demo/panels/ha-panel-dev-state.html', + url_name: 'dev-state', + }, + 'dev-template': { + component_name: 'dev-template', + url: '/demo/panels/ha-panel-dev-template.html', + url_name: 'dev-template', + }, + history: { + component_name: 'history', + icon: 'mdi:poll-box', + title: 'History', + url: '/demo/panels/ha-panel-history.html', + url_name: 'history', + }, + logbook: { + component_name: 'logbook', + icon: 'mdi:format-list-bulleted-type', + title: 'Logbook', + url: '/demo/panels/ha-panel-logbook.html', + url_name: 'logbook', + }, + map: { + component_name: 'map', + icon: 'mdi:account-location', + title: 'Map', + url: '/demo/panels/ha-panel-map.html', + url_name: 'map', + }, +}; diff --git a/demo_data/service_data.js b/demo_data/service_data.js new file mode 100755 index 0000000000..d3d289e9e2 --- /dev/null +++ b/demo_data/service_data.js @@ -0,0 +1,37 @@ +export default [ + { + domain: 'homeassistant', + services: { + stop: { description: '', fields: {} }, + turn_off: { description: '', fields: {} }, + turn_on: { description: '', fields: {} }, + }, + }, + { + domain: 'light', + services: { + turn_off: { description: '', fields: {} }, + turn_on: { description: '', fields: {} }, + }, + }, + { + domain: 'switch', + services: { + turn_off: { description: '', fields: {} }, + turn_on: { description: '', fields: {} }, + }, + }, + { + domain: 'input_boolean', + services: { + turn_off: { description: '', fields: {} }, + turn_on: { description: '', fields: {} }, + }, + }, + { + domain: 'configurator', + services: { + configure: { description: '', fields: {} }, + }, + }, +]; diff --git a/demo_data/state_data.js b/demo_data/state_data.js new file mode 100755 index 0000000000..8cca2c6270 --- /dev/null +++ b/demo_data/state_data.js @@ -0,0 +1,279 @@ +function getRandomTime() { + const ts = new Date(new Date().getTime() - (Math.random() * 80 * 60 * 1000)); + return ts.toISOString(); +} + +const entities = []; + +function addEntity(entityId, state, attributes = {}) { + entities.push({ + state, + attributes, + entity_id: entityId, + last_changed: getRandomTime(), + last_updated: getRandomTime(), + }); +} + +let groupOrder = 0; + +function addGroup(objectId, state, entityIds, name, view) { + groupOrder++; + + const attributes = { + entity_id: entityIds, + order: groupOrder, + }; + + if (name) { + attributes.friendly_name = name; + } + if (view) { + attributes.view = view; + attributes.hidden = true; + } + addEntity(`group.${objectId}`, state, attributes); +} + +// --------------------------------------------------- +// HOME ASSISTANT +// --------------------------------------------------- +addEntity('a.demo_mode', 'enabled'); + +addEntity('configurator.philips_hue', 'configure', { + configure_id: '4415244496-1', + description: 'Press the button on the bridge to register Philips Hue with Home Assistant.', + description_image: '/demo/images/config_philips_hue.jpg', + fields: [], + submit_caption: 'I have pressed the button', + friendly_name: 'Philips Hue', +}); + +// --------------------------------------------------- +// VIEWS +// --------------------------------------------------- + +addGroup( + 'default_view', 'on', [ + 'a.demo_mode', + 'sensor.humidity', + 'sensor.temperature', + 'device_tracker.paulus', + 'device_tracker.anne_therese', + 'configurator.philips_hue', + 'group.cooking', + 'group.general', + 'group.rooms', + 'camera.living_room', + 'media_player.living_room', + 'scene.romantic', + 'scene.good_morning', + 'script.water_lawn', + ], 'Main', true); + +addGroup( + 'rooms_view', 'on', [ + 'group.living_room', + 'group.bedroom', + ], 'Rooms', true); + +addGroup('rooms', 'on', ['group.living_room', 'group.bedroom'], 'Rooms'); + +// --------------------------------------------------- +// DEVICE TRACKER + ZONES +// --------------------------------------------------- + +addEntity('device_tracker.anne_therese', 'school', { + entity_picture: 'https://graph.facebook.com/621994601/picture', + friendly_name: 'Anne Therese', + latitude: 32.879898, + longitude: -117.236776, + gps_accuracy: 250, + battery: 76, +}); + +addEntity('device_tracker.paulus', 'not_home', { + entity_picture: 'https://graph.facebook.com/297400035/picture', + friendly_name: 'Paulus', + gps_accuracy: 75, + latitude: 32.892950, + longitude: -117.203431, + battery: 56, +}); + +addEntity('zone.school', 'zoning', { + radius: 250, + latitude: 32.880834, + longitude: -117.237556, + icon: 'mdi:library', + hidden: true, +}); + +addEntity('zone.work', 'zoning', { + radius: 250, + latitude: 32.896844, + longitude: -117.202204, + icon: 'mdi:worker', + hidden: true, +}); + +addEntity('zone.home', 'zoning', { + radius: 100, + latitude: 32.873708, + longitude: -117.226590, + icon: 'mdi:home', + hidden: true, +}); + +// --------------------------------------------------- +// GENERAL +// --------------------------------------------------- +addGroup('general', 'on', [ + 'alarm_control_panel.home', + 'garage_door.garage_door', + 'lock.kitchen_door', + 'thermostat.nest', + 'camera.living_room', +]); + +addEntity('camera.living_room', 'idle', { + entity_picture: '/demo/webcam.jpg?', +}); + +addEntity('garage_door.garage_door', 'open', { + friendly_name: 'Garage Door', +}); + +addEntity('alarm_control_panel.home', 'armed_home', { + friendly_name: 'Alarm', + code_format: '^\\d{4}', +}); + +addEntity('lock.kitchen_door', 'open', { + friendly_name: 'Kitchen Door', +}); + +// --------------------------------------------------- +// PRESETS +// --------------------------------------------------- + +addEntity('script.water_lawn', 'off', { + friendly_name: 'Water Lawn', +}); +addEntity('scene.romantic', 'scening', { + friendly_name: 'Romantic', +}); +// addEntity('scene.good_morning', 'scening', { +// friendly_name: 'Good Morning', +// }); + +// --------------------------------------------------- +// LIVING ROOM +// --------------------------------------------------- + +addGroup( + 'living_room', 'on', + [ + 'light.table_lamp', + 'light.ceiling', + 'light.tv_back_light', + 'switch.ac', + 'media_player.living_room', + ], + 'Living Room' +); + +addEntity('light.tv_back_light', 'off', { + friendly_name: 'TV Back Light', +}); +addEntity('light.ceiling', 'on', { + friendly_name: 'Ceiling Lights', + brightness: 200, + rgb_color: [255, 116, 155], +}); +addEntity('light.table_lamp', 'on', { + brightness: 200, + rgb_color: [150, 212, 94], + friendly_name: 'Table Lamp', +}); +addEntity('switch.ac', 'on', { + friendly_name: 'AC', + icon: 'mdi:air-conditioner', +}); +addEntity('media_player.living_room', 'playing', { + entity_picture: '/demo/images/thrones.jpg', + friendly_name: 'Chromecast', + supported_media_commands: 509, + media_content_type: 'tvshow', + media_title: 'The Dance of Dragons', + media_series_title: 'Game of Thrones', + media_season: 5, + media_episode: '09', + app_name: 'HBO Now', +}); + +// --------------------------------------------------- +// BEDROOM +// --------------------------------------------------- + +addGroup( + 'bedroom', 'off', + [ + 'light.bed_light', + 'switch.decorative_lights', + 'rollershutter.bedroom_window', + ], + 'Bedroom' +); + +addEntity('switch.decorative_lights', 'off', { + friendly_name: 'Decorative Lights', +}); +addEntity('light.bed_light', 'off', { + friendly_name: 'Bed Light', +}); +addEntity('rollershutter.bedroom_window', 'closed', { + friendly_name: 'Window', + current_position: 0, +}); + +// --------------------------------------------------- +// SENSORS +// --------------------------------------------------- + +addEntity('sensor.temperature', '15.6', { + unit_of_measurement: '\u00b0C', + friendly_name: 'Temperature', +}); +addEntity('sensor.humidity', '54', { + unit_of_measurement: '%', + friendly_name: 'Humidity', +}); + +addEntity('thermostat.nest', '23', { + away_mode: 'off', + temperature: '21', + current_temperature: '18', + unit_of_measurement: '\u00b0C', + friendly_name: 'Nest', +}); + +// --------------------------------------------------- +// COOKING AUTOMATION +// --------------------------------------------------- +addEntity('input_select.cook_today', 'Paulus', { + options: ['Paulus', 'Anne Therese'], + icon: 'mdi:panda', +}); + +addEntity('input_boolean.notify_cook', 'on', { + icon: 'mdi:alarm', + friendly_name: 'Notify Cook', +}); + +addGroup( + 'cooking', 'unknown', + ['input_select.cook_today', 'input_boolean.notify_cook'] +); + +export default entities; diff --git a/demo_data/state_history_data.js b/demo_data/state_history_data.js new file mode 100755 index 0000000000..4d540ffe35 --- /dev/null +++ b/demo_data/state_history_data.js @@ -0,0 +1,257 @@ +import objectAssign from 'object-assign'; + +import stateData from './state_data'; + +function getTime(minutesAgo) { + const ts = new Date(Date.now() - (minutesAgo * 60 * 1000)); + return ts.toISOString(); +} + +// prefill with entities we do not want to track +const seen = { + 'a.demo_mode': true, + 'configurator.philips_hue': true, + 'group.default_view': true, + 'group.rooms_view': true, + 'group.rooms': true, + 'zone.school': true, + 'zone.work': true, + 'zone.home': true, + 'group.general': true, + 'camera.roundabout': true, + 'script.water_lawn': true, + 'scene.romantic': true, + 'scene.good_morning': true, + 'group.cooking': true, +}; +const history = []; + +function randomTimeAdjustment(diff) { + return Math.random() * diff - (diff / 2); +} + +const maxTime = 1440; + +function addEntity(state, deltas) { + seen[state.entity_id] = true; + let changes; + if (typeof deltas[0] === 'string') { + changes = deltas.map(state_ => ({ state: state_ })); + } else { + changes = deltas; + } + + const timeDiff = (900 / changes.length); + + history.push(changes.map( + (change, index) => { + let attributes; + if (!change.attributes && !state.attributes) { + attributes = {}; + } else if (!change.attributes) { + attributes = state.attributes; + } else if (!state.attributes) { + attributes = change.attributes; + } else { + attributes = objectAssign({}, state.attributes, change.attributes); + } + + const time = index === 0 ? getTime(maxTime) : getTime(maxTime - index * timeDiff + + randomTimeAdjustment(timeDiff)); + + return { + attributes, + entity_id: state.entity_id, + state: change.state || state.state, + last_changed: time, + last_updated: time, + }; + })); +} + +addEntity( + { + entity_id: 'sensor.humidity', + attributes: { + unit_of_measurement: '%', + }, + }, ['45', '49', '52', '49', '52', '49', '45', '42'] +); + +addEntity( + { + entity_id: 'sensor.temperature', + attributes: { + unit_of_measurement: '\u00b0C', + }, + }, ['23', '27', '25', '23', '24'] +); + +addEntity( + { + entity_id: 'thermostat.nest', + attributes: { + unit_of_measurement: '\u00b0C', + }, + }, [ + { + state: '23', + attributes: { + current_temperature: 20, + temperature: 23, + }, + }, + { + state: '23', + attributes: { + current_temperature: 22, + temperature: 23, + }, + }, + { + state: '20', + attributes: { + current_temperature: 21, + temperature: 20, + }, + }, + { + state: '20', + attributes: { + current_temperature: 20, + temperature: 20, + }, + }, + { + state: '20', + attributes: { + current_temperature: 19, + temperature: 20, + }, + }, + ] +); + +addEntity( + { + entity_id: 'media_player.living_room', + attributes: { + friendly_name: 'Chromecast', + }, + }, ['Plex', 'idle', 'YouTube', 'Netflix', 'idle', 'Plex'] +); + +addEntity( + { + entity_id: 'group.all_devices', + }, ['home', 'not_home', 'home'] +); + +addEntity( + { + entity_id: 'device_tracker.paulus', + }, ['home', 'not_home', 'work', 'not_home'] +); + +addEntity( + { + entity_id: 'device_tracker.anne_therese', + }, ['home', 'not_home', 'home', 'not_home', 'school'] +); + +addEntity( + { + entity_id: 'garage_door.garage_door', + }, ['open', 'closed', 'open'] +); + +addEntity( + { + entity_id: 'alarm_control_panel.home', + }, ['disarmed', 'pending', 'armed_home', 'pending', 'disarmed', 'pending', 'armed_home'] +); + +addEntity( + { + entity_id: 'lock.kitchen_door', + }, ['unlocked', 'locked', 'unlocked', 'locked'] +); + +addEntity( + { + entity_id: 'light.tv_back_light', + }, ['on', 'off', 'on', 'off'] +); + +addEntity( + { + entity_id: 'light.ceiling', + }, ['on', 'off', 'on'] +); + +addEntity( + { + entity_id: 'light.table_lamp', + }, ['on', 'off', 'on'] +); + +addEntity( + { + entity_id: 'switch.ac', + }, ['on', 'off', 'on'] +); + +addEntity( + { + entity_id: 'group.bedroom', + }, ['on', 'off', 'on', 'off'] +); + +addEntity( + { + entity_id: 'group.living_room', + }, ['on', 'off', 'on'] +); + +addEntity( + { + entity_id: 'switch.decorative_lights', + }, ['on', 'off', 'on', 'off'] +); + +addEntity( + { + entity_id: 'light.bed_light', + }, ['on', 'off', 'on', 'off'] +); + +addEntity( + { + entity_id: 'rollershutter.bedroom_window', + }, ['open', 'closed', 'open', 'closed'] +); + +addEntity( + { + entity_id: 'input_select.cook_today', + }, ['Anne Therese', 'Paulus'] +); + +addEntity( + { + entity_id: 'input_boolean.notify_cook', + }, ['off', 'on'] +); + +if (__DEV__) { + for (let i = 0; i < stateData.length; i++) { + const entity = stateData[i]; + if (!(entity.entity_id in seen)) { + /* eslint-disable no-console */ + console.warn(`Missing history for ${entity.entity_id}`); + /* eslint-enable no-console */ + } + } +} + +export default history; diff --git a/rollup/demo.js b/rollup/demo.js index 94574b6ffb..572d4b4513 100644 --- a/rollup/demo.js +++ b/rollup/demo.js @@ -1,7 +1,7 @@ import config from './base-config'; export default Object.assign({}, config, { - entry: 'home-assistant-js/demo_data/expose_window.js', + entry: 'demo_data/expose_window.js', targets: [ { dest: 'build-temp/demo_data.js', format: 'iife' }, ],