home-assistant-query-selector 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -5
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Easily query [Home Assistant] DOM elements in an asynchronous way.
|
|
4
4
|
|
|
5
|
-
[](https://github.com/elchininet/home-assistant-query-selector/actions/workflows/deploy.yaml)
|
|
5
|
+
[](https://github.com/elchininet/home-assistant-query-selector/actions/workflows/deploy.yaml)
|
|
6
|
+
[](https://github.com/elchininet/home-assistant-query-selector/actions/workflows/tests.yaml)
|
|
7
|
+
[](https://coveralls.io/github/elchininet/home-assistant-query-selector?branch=master)
|
|
8
|
+
[](https://badge.fury.io/js/home-assistant-query-selector)
|
|
9
|
+
|
|
10
|
+
[](https://github.com/elchininet/home-assistant-query-selector/actions/workflows/ha-beta-tests.yaml)
|
|
6
11
|
|
|
7
12
|
## Introduction
|
|
8
13
|
|
|
@@ -149,13 +154,15 @@ new HAQuerySelector([config])
|
|
|
149
154
|
{
|
|
150
155
|
retries?: number;
|
|
151
156
|
delay?: number;
|
|
157
|
+
eventThreshold?: number;
|
|
152
158
|
}
|
|
153
159
|
```
|
|
154
160
|
|
|
155
|
-
| Parameter
|
|
156
|
-
|
|
|
157
|
-
| retries
|
|
158
|
-
| delay
|
|
161
|
+
| Parameter | Optional | Description |
|
|
162
|
+
| -------------- | ------------- | --------------------------------------------------- |
|
|
163
|
+
| retries | yes | How many retries trying to find an element in the DOM tree before giving up (defaults to 100) |
|
|
164
|
+
| delay | yes | Delay between each retry trying to find an element in the DOM tree (defaults to 50) |
|
|
165
|
+
| eventThreshold | yes | Timestamp threshold to fire an event. If two consecutive events of the same type have a timestamp difference lower than this value, the second event will be ignored (defaults to 450) |
|
|
159
166
|
|
|
160
167
|
### Public methods
|
|
161
168
|
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AsyncSelector, AsyncParams } from "shadow-dom-selector";
|
|
2
|
-
type HAQuerySelectorConfig = AsyncParams
|
|
2
|
+
type HAQuerySelectorConfig = AsyncParams & {
|
|
3
|
+
eventThreshold?: number;
|
|
4
|
+
};
|
|
3
5
|
type NodeDescriptorProps = {
|
|
4
6
|
selector: string;
|
|
5
7
|
children?: HomeAssistantNodeDescriptor;
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{asyncQuerySelector as e,AsyncSelector as t}from"shadow-dom-selector";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},o(e,t)};var _=function(){return _=Object.assign||function(e){for(var t,o=1,_=arguments.length;o<_;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},_.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n,r,O,i,s,a,A,l,c,E,h,I,N,
|
|
1
|
+
import{asyncQuerySelector as e,AsyncSelector as t}from"shadow-dom-selector";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},o(e,t)};var _=function(){return _=Object.assign||function(e){for(var t,o=1,_=arguments.length;o<_;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},_.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n,r,O,i,s,a,A,l,c,E,h,I,d,N,L,R,u="$",D={retries:100,delay:50,eventThreshold:450};!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR",e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER"}(n||(n={})),function(e){e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(r||(r={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(O||(O={})),function(e){e.ON_LISTEN="onListen",e.ON_PANEL_LOAD="onPanelLoad",e.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",e.ON_MORE_INFO_DIALOG_OPEN="onMoreInfoDialogOpen",e.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onHistoryAndLogBookDialogOpen",e.ON_SETTINGS_DIALOG_OPEN="onSettingsDialogOpen"}(i||(i={})),function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(R||(R={}));var v=((s={})[n.HOME_ASSISTANT]={selector:R.HOME_ASSISTANT,children:{shadowRoot:{selector:u,children:(a={},a[n.HOME_ASSISTANT_MAIN]={selector:R.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:u,children:(A={},A[n.HA_DRAWER]={selector:R.HA_DRAWER,children:(l={},l[n.HA_SIDEBAR]={selector:R.HA_SIDEBAR,children:{shadowRoot:{selector:u}}},l[n.PARTIAL_PANEL_RESOLVER]={selector:R.PARTIAL_PANEL_RESOLVER},l)},A)}}},a)}}},s),H=((c={})[r.HA_PANEL_LOVELACE]={selector:R.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:u,children:(E={},E[r.HUI_ROOT]={selector:R.HUI_ROOT,children:{shadowRoot:{selector:u,children:(h={},h[r.HEADER]={selector:R.HEADER},h[r.HUI_VIEW]={selector:R.HUI_VIEW},h)}}},E)}}},c),p={shadowRoot:{selector:u,children:(I={},I[O.HA_MORE_INFO_DIALOG]={selector:R.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:u,children:(d={},d[O.HA_DIALOG]={selector:R.HA_DIALOG,children:(N={},N[O.HA_DIALOG_CONTENT]={selector:R.HA_DIALOG_CONTENT,children:(L={},L[O.HA_MORE_INFO_DIALOG_INFO]={selector:R.HA_MORE_INFO_DIALOG_INFO},L[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]={selector:R.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},L[O.HA_DIALOG_MORE_INFO_SETTINGS]={selector:R.HA_DIALOG_MORE_INFO_SETTINGS},L)},N)},d)}}},I)}},f=function(o,n,r,O){return void 0===r&&(r=null),void 0===O&&(O=!1),Object.entries(n||{}).reduce((function(n,i){var s=i[0],a=i[1];if(a.selector===u&&r)return a.children?_(_({},n),f(o,a.children,r,!0)):n;var A=r?r.then((function(t){return t?e(t,(_=a.selector,O?"$ "+_:_),o):null;var _})):e(a.selector,o);return n[s]={element:A,children:f(o,a.children,A),selector:new t(A,o)},n}),{})},T=function(e,t){for(var o=0,_=Object.entries(t);o<_.length;o++){var n=_[o];if(n[0]===e)return n[1];var r=T(e,n[1].children);if(r)return r}},S=function(e,t){return Object.keys(e).reduce((function(e,o){var n=T(o,t);n.children;var r=function(e,t){var o={};for(var _ in e)Object.prototype.hasOwnProperty.call(e,_)&&t.indexOf(_)<0&&(o[_]=e[_]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(_=Object.getOwnPropertySymbols(e);n<_.length;n++)t.indexOf(_[n])<0&&Object.prototype.propertyIsEnumerable.call(e,_[n])&&(o[_[n]]=e[_[n]])}return o}(n,["children"]);return e[o]=_({},r),e}),{})},G=function(){function e(){this.delegate=document.createDocumentFragment()}return e.prototype.addEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=this.delegate).addEventListener.apply(e,t)},e.prototype.dispatchEvent=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).dispatchEvent.apply(e,t)},e.prototype.removeEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).removeEventListener.apply(e,t)},e}(),m=function(e){function t(t){void 0===t&&(t={});var o=e.call(this)||this;return o._config=_(_({},D),t),o._timestaps={},o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function _(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(_.prototype=t.prototype,new _)}(t,e),t.prototype._dispatchEvent=function(e,t){var o=Date.now();o-this._timestaps[e]<this._config.eventThreshold||(this._timestaps[e]=o,this.dispatchEvent(new CustomEvent(e,{detail:t})))},t.prototype._updateDialogElements=function(e){var t,o=this;void 0===e&&(e=O.HA_MORE_INFO_DIALOG_INFO),this._dialogTree=f(this._config,p,this._haRootElements.HOME_ASSISTANT.element);var _=S(O,this._dialogTree);_.HA_DIALOG_CONTENT.element.then((function(e){o._dialogsContentObserver.disconnect(),o._dialogsContentObserver.observe(e,{childList:!0})})),this._haDialogElements=function(e,t){return[O.HA_MORE_INFO_DIALOG,O.HA_DIALOG,O.HA_DIALOG_CONTENT,t].reduce((function(t,o){return t[o]=e[o],t}),{})}(_,e);var n=((t={})[O.HA_MORE_INFO_DIALOG_INFO]=i.ON_MORE_INFO_DIALOG_OPEN,t[O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=i.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN,t[O.HA_DIALOG_MORE_INFO_SETTINGS]=i.ON_SETTINGS_DIALOG_OPEN,t);this._dispatchEvent(n[e],this._haDialogElements)},t.prototype._updateRootElements=function(){var e=this;this._homeAssistantRootTree=f(this._config,v),this._haRootElements=S(n,this._homeAssistantRootTree),this._haRootElements[n.HOME_ASSISTANT].selector.$.element.then((function(t){e._dialogsObserver.disconnect(),e._dialogsObserver.observe(t,{childList:!0})})),this._haRootElements[n.PARTIAL_PANEL_RESOLVER].element.then((function(t){e._panelResolverObserver.disconnect(),t&&e._panelResolverObserver.observe(t,{subtree:!0,childList:!0})})),this._dispatchEvent(i.ON_LISTEN,this._haRootElements),this._dispatchEvent(i.ON_PANEL_LOAD,this._haRootElements)},t.prototype._updateLovelaceElements=function(){var e=this;this._homeAssistantResolverTree=f(this._config,H,this._haRootElements[n.HA_DRAWER].element),this._haResolverElements=S(r,this._homeAssistantResolverTree),this._haResolverElements[r.HA_PANEL_LOVELACE].element.then((function(t){e._lovelaceObserver.disconnect(),t&&(e._lovelaceObserver.observe(t.shadowRoot,{childList:!0}),e._dispatchEvent(i.ON_LOVELACE_PANEL_LOAD,_(_({},e._haRootElements),e._haResolverElements)))}))},t.prototype._watchDialogs=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===R.HA_MORE_INFO_DIALOG&&t._updateDialogElements()}))}))},t.prototype._watchDialogsContent=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){var o,_=((o={})[R.HA_MORE_INFO_DIALOG_INFO]=O.HA_MORE_INFO_DIALOG_INFO,o[R.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=O.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,o[R.HA_DIALOG_MORE_INFO_SETTINGS]=O.HA_DIALOG_MORE_INFO_SETTINGS,o);if(e.localName&&e.localName in _){var n=e.localName;t._updateDialogElements(_[n])}}))}))},t.prototype._watchDashboards=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){t._dispatchEvent(i.ON_PANEL_LOAD,t._haRootElements),e.localName===R.HA_PANEL_LOVELACE&&t._updateLovelaceElements()}))}))},t.prototype._watchLovelace=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===R.HUI_ROOT&&t._updateLovelaceElements()}))}))},t.prototype.listen=function(){this._watchDialogsBinded=this._watchDialogs.bind(this),this._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateLovelaceElements()},t.prototype.addEventListener=function(t,o,_){e.prototype.addEventListener.call(this,t,o,_)},t}(G);export{m as HAQuerySelector,i as HAQuerySelectorEvent};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { AsyncSelector, AsyncParams } from "shadow-dom-selector";
|
|
2
|
-
type HAQuerySelectorConfig = AsyncParams
|
|
2
|
+
type HAQuerySelectorConfig = AsyncParams & {
|
|
3
|
+
eventThreshold?: number;
|
|
4
|
+
};
|
|
3
5
|
type NodeDescriptorProps = {
|
|
4
6
|
selector: string;
|
|
5
7
|
children?: HomeAssistantNodeDescriptor;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("shadow-dom-selector"),t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},t(e,o)};var o=function(){return o=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var _ in t=arguments[o])Object.prototype.hasOwnProperty.call(t,_)&&(e[_]=t[_]);return e},o.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n,_,r,O,
|
|
1
|
+
"use strict";var e=require("shadow-dom-selector"),t=function(e,o){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},t(e,o)};var o=function(){return o=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var _ in t=arguments[o])Object.prototype.hasOwnProperty.call(t,_)&&(e[_]=t[_]);return e},o.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var n,_,r,s,O,i,a,A,c,l,E,h,I,d,N,L,u="$",R={retries:100,delay:50,eventThreshold:450};!function(e){e.HOME_ASSISTANT="HOME_ASSISTANT",e.HOME_ASSISTANT_MAIN="HOME_ASSISTANT_MAIN",e.HA_DRAWER="HA_DRAWER",e.HA_SIDEBAR="HA_SIDEBAR",e.PARTIAL_PANEL_RESOLVER="PARTIAL_PANEL_RESOLVER"}(n||(n={})),function(e){e.HA_PANEL_LOVELACE="HA_PANEL_LOVELACE",e.HUI_ROOT="HUI_ROOT",e.HEADER="HEADER",e.HUI_VIEW="HUI_VIEW"}(_||(_={})),function(e){e.HA_MORE_INFO_DIALOG="HA_MORE_INFO_DIALOG",e.HA_DIALOG="HA_DIALOG",e.HA_DIALOG_CONTENT="HA_DIALOG_CONTENT",e.HA_MORE_INFO_DIALOG_INFO="HA_MORE_INFO_DIALOG_INFO",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK",e.HA_DIALOG_MORE_INFO_SETTINGS="HA_DIALOG_MORE_INFO_SETTINGS"}(r||(r={})),exports.HAQuerySelectorEvent=void 0,(s=exports.HAQuerySelectorEvent||(exports.HAQuerySelectorEvent={})).ON_LISTEN="onListen",s.ON_PANEL_LOAD="onPanelLoad",s.ON_LOVELACE_PANEL_LOAD="onLovelacePanelLoad",s.ON_MORE_INFO_DIALOG_OPEN="onMoreInfoDialogOpen",s.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN="onHistoryAndLogBookDialogOpen",s.ON_SETTINGS_DIALOG_OPEN="onSettingsDialogOpen",function(e){e.HOME_ASSISTANT="home-assistant",e.HOME_ASSISTANT_MAIN="home-assistant-main",e.HA_DRAWER="ha-drawer",e.HA_SIDEBAR="ha-sidebar",e.PARTIAL_PANEL_RESOLVER="partial-panel-resolver",e.HA_PANEL_LOVELACE="ha-panel-lovelace",e.HUI_ROOT="hui-root",e.HEADER=".header",e.HUI_VIEW="hui-view",e.HA_MORE_INFO_DIALOG="ha-more-info-dialog",e.HA_DIALOG="ha-dialog",e.HA_DIALOG_CONTENT=".content",e.HA_MORE_INFO_DIALOG_INFO="ha-more-info-info",e.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK="ha-more-info-history-and-logbook",e.HA_DIALOG_MORE_INFO_SETTINGS="ha-more-info-settings"}(L||(L={}));var v=((O={})[n.HOME_ASSISTANT]={selector:L.HOME_ASSISTANT,children:{shadowRoot:{selector:u,children:(i={},i[n.HOME_ASSISTANT_MAIN]={selector:L.HOME_ASSISTANT_MAIN,children:{shadowRoot:{selector:u,children:(a={},a[n.HA_DRAWER]={selector:L.HA_DRAWER,children:(A={},A[n.HA_SIDEBAR]={selector:L.HA_SIDEBAR,children:{shadowRoot:{selector:u}}},A[n.PARTIAL_PANEL_RESOLVER]={selector:L.PARTIAL_PANEL_RESOLVER},A)},a)}}},i)}}},O),H=((c={})[_.HA_PANEL_LOVELACE]={selector:L.HA_PANEL_LOVELACE,children:{shadowRoot:{selector:u,children:(l={},l[_.HUI_ROOT]={selector:L.HUI_ROOT,children:{shadowRoot:{selector:u,children:(E={},E[_.HEADER]={selector:L.HEADER},E[_.HUI_VIEW]={selector:L.HUI_VIEW},E)}}},l)}}},c),p={shadowRoot:{selector:u,children:(h={},h[r.HA_MORE_INFO_DIALOG]={selector:L.HA_MORE_INFO_DIALOG,children:{shadowRoot:{selector:u,children:(I={},I[r.HA_DIALOG]={selector:L.HA_DIALOG,children:(d={},d[r.HA_DIALOG_CONTENT]={selector:L.HA_DIALOG_CONTENT,children:(N={},N[r.HA_MORE_INFO_DIALOG_INFO]={selector:L.HA_MORE_INFO_DIALOG_INFO},N[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]={selector:L.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK},N[r.HA_DIALOG_MORE_INFO_SETTINGS]={selector:L.HA_DIALOG_MORE_INFO_SETTINGS},N)},d)},I)}}},h)}},D=function(t,n,_,r){return void 0===_&&(_=null),void 0===r&&(r=!1),Object.entries(n||{}).reduce((function(n,s){var O=s[0],i=s[1];if(i.selector===u&&_)return i.children?o(o({},n),D(t,i.children,_,!0)):n;var a=_?_.then((function(o){return o?e.asyncQuerySelector(o,(n=i.selector,r?"$ "+n:n),t):null;var n})):e.asyncQuerySelector(i.selector,t);return n[O]={element:a,children:D(t,i.children,a),selector:new e.AsyncSelector(a,t)},n}),{})},S=function(e,t){for(var o=0,n=Object.entries(t);o<n.length;o++){var _=n[o];if(_[0]===e)return _[1];var r=S(e,_[1].children);if(r)return r}},f=function(e,t){return Object.keys(e).reduce((function(e,n){var _=S(n,t);_.children;var r=function(e,t){var o={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(o[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var _=0;for(n=Object.getOwnPropertySymbols(e);_<n.length;_++)t.indexOf(n[_])<0&&Object.prototype.propertyIsEnumerable.call(e,n[_])&&(o[n[_]]=e[n[_]])}return o}(_,["children"]);return e[n]=o({},r),e}),{})},T=function(){function e(){this.delegate=document.createDocumentFragment()}return e.prototype.addEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=this.delegate).addEventListener.apply(e,t)},e.prototype.dispatchEvent=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).dispatchEvent.apply(e,t)},e.prototype.removeEventListener=function(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return(e=this.delegate).removeEventListener.apply(e,t)},e}(),G=function(e){function s(t){void 0===t&&(t={});var n=e.call(this)||this;return n._config=o(o({},R),t),n._timestaps={},n}return function(e,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function n(){this.constructor=e}t(e,o),e.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}(s,e),s.prototype._dispatchEvent=function(e,t){var o=Date.now();o-this._timestaps[e]<this._config.eventThreshold||(this._timestaps[e]=o,this.dispatchEvent(new CustomEvent(e,{detail:t})))},s.prototype._updateDialogElements=function(e){var t,o=this;void 0===e&&(e=r.HA_MORE_INFO_DIALOG_INFO),this._dialogTree=D(this._config,p,this._haRootElements.HOME_ASSISTANT.element);var n=f(r,this._dialogTree);n.HA_DIALOG_CONTENT.element.then((function(e){o._dialogsContentObserver.disconnect(),o._dialogsContentObserver.observe(e,{childList:!0})})),this._haDialogElements=function(e,t){return[r.HA_MORE_INFO_DIALOG,r.HA_DIALOG,r.HA_DIALOG_CONTENT,t].reduce((function(t,o){return t[o]=e[o],t}),{})}(n,e);var _=((t={})[r.HA_MORE_INFO_DIALOG_INFO]=exports.HAQuerySelectorEvent.ON_MORE_INFO_DIALOG_OPEN,t[r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=exports.HAQuerySelectorEvent.ON_HISTORY_AND_LOGBOOK_DIALOG_OPEN,t[r.HA_DIALOG_MORE_INFO_SETTINGS]=exports.HAQuerySelectorEvent.ON_SETTINGS_DIALOG_OPEN,t);this._dispatchEvent(_[e],this._haDialogElements)},s.prototype._updateRootElements=function(){var e=this;this._homeAssistantRootTree=D(this._config,v),this._haRootElements=f(n,this._homeAssistantRootTree),this._haRootElements[n.HOME_ASSISTANT].selector.$.element.then((function(t){e._dialogsObserver.disconnect(),e._dialogsObserver.observe(t,{childList:!0})})),this._haRootElements[n.PARTIAL_PANEL_RESOLVER].element.then((function(t){e._panelResolverObserver.disconnect(),t&&e._panelResolverObserver.observe(t,{subtree:!0,childList:!0})})),this._dispatchEvent(exports.HAQuerySelectorEvent.ON_LISTEN,this._haRootElements),this._dispatchEvent(exports.HAQuerySelectorEvent.ON_PANEL_LOAD,this._haRootElements)},s.prototype._updateLovelaceElements=function(){var e=this;this._homeAssistantResolverTree=D(this._config,H,this._haRootElements[n.HA_DRAWER].element),this._haResolverElements=f(_,this._homeAssistantResolverTree),this._haResolverElements[_.HA_PANEL_LOVELACE].element.then((function(t){e._lovelaceObserver.disconnect(),t&&(e._lovelaceObserver.observe(t.shadowRoot,{childList:!0}),e._dispatchEvent(exports.HAQuerySelectorEvent.ON_LOVELACE_PANEL_LOAD,o(o({},e._haRootElements),e._haResolverElements)))}))},s.prototype._watchDialogs=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===L.HA_MORE_INFO_DIALOG&&t._updateDialogElements()}))}))},s.prototype._watchDialogsContent=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){var o,n=((o={})[L.HA_MORE_INFO_DIALOG_INFO]=r.HA_MORE_INFO_DIALOG_INFO,o[L.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK]=r.HA_DIALOG_MORE_INFO_HISTORY_AND_LOGBOOK,o[L.HA_DIALOG_MORE_INFO_SETTINGS]=r.HA_DIALOG_MORE_INFO_SETTINGS,o);if(e.localName&&e.localName in n){var _=e.localName;t._updateDialogElements(n[_])}}))}))},s.prototype._watchDashboards=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){t._dispatchEvent(exports.HAQuerySelectorEvent.ON_PANEL_LOAD,t._haRootElements),e.localName===L.HA_PANEL_LOVELACE&&t._updateLovelaceElements()}))}))},s.prototype._watchLovelace=function(e){var t=this;e.forEach((function(e){e.addedNodes.forEach((function(e){e.localName===L.HUI_ROOT&&t._updateLovelaceElements()}))}))},s.prototype.listen=function(){this._watchDialogsBinded=this._watchDialogs.bind(this),this._watchDialogsContentBinded=this._watchDialogsContent.bind(this),this._watchDashboardsBinded=this._watchDashboards.bind(this),this._watchLovelaceBinded=this._watchLovelace.bind(this),this._dialogsObserver=new MutationObserver(this._watchDialogsBinded),this._dialogsContentObserver=new MutationObserver(this._watchDialogsContentBinded),this._panelResolverObserver=new MutationObserver(this._watchDashboardsBinded),this._lovelaceObserver=new MutationObserver(this._watchLovelaceBinded),this._updateRootElements(),this._updateLovelaceElements()},s.prototype.addEventListener=function(t,o,n){e.prototype.addEventListener.call(this,t,o,n)},s}(T);exports.HAQuerySelector=G;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "home-assistant-query-selector",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Easily query home-assistant DOM elements in an async way",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"query-selector",
|
|
@@ -45,10 +45,11 @@
|
|
|
45
45
|
"test:run": "playwright test",
|
|
46
46
|
"test:open": "playwright test --ui",
|
|
47
47
|
"test:ci": "yarn demo:ha && yarn start:playwright && yarn stop:ha",
|
|
48
|
-
"start:ha": "docker run --rm -d -p8123:8123 -v ${PWD}/.hass/config:/config homeassistant/home-assistant
|
|
49
|
-
"stop:ha": "docker stop $(docker ps -a -q --filter ancestor=homeassistant/home-assistant
|
|
48
|
+
"start:ha": "docker run --rm -d -p8123:8123 -v ${PWD}/.hass/config:/config homeassistant/home-assistant:${TAG:-$(cat .hass/config/.HA_VERSION)}",
|
|
49
|
+
"stop:ha": "docker stop $(docker ps -a -q --filter ancestor=homeassistant/home-assistant:${TAG:-$(cat .hass/config/.HA_VERSION)}) || true",
|
|
50
|
+
"reset:ha": "git add .hass/config/.HA_VERSION && git checkout .hass/config",
|
|
50
51
|
"demo:ha": "yarn test:clean && yarn build && yarn start:ha",
|
|
51
|
-
"start:playwright": "docker run --rm --network host --add-host host.docker.internal:host-gateway -v $(pwd):/$(pwd)/ -w $(pwd) -i mcr.microsoft.com/playwright
|
|
52
|
+
"start:playwright": "docker run --rm --network host --add-host host.docker.internal:host-gateway -v $(pwd):/$(pwd)/ -w $(pwd) -i mcr.microsoft.com/playwright:$(cat .playwright_docker_version) sh -c \"yarn test:run && exit\"",
|
|
52
53
|
"prepare": "yarn build",
|
|
53
54
|
"prepublishOnly": "yarn lint && yarn test:ts && yarn test:ci",
|
|
54
55
|
"version": "git add .",
|