mirror of
https://github.com/CCOSTAN/Home-AssistantConfig.git
synced 2025-02-09 00:55:34 +00:00
4 lines
26 KiB
JavaScript
4 lines
26 KiB
JavaScript
|
import{c_ as e,dW as t,dX as n,dY as a,dZ as r,d_ as i,l as s,d$ as o,e0 as c,e1 as g,e2 as l,d6 as u,dP as m,k as d,i as f,dc as h,e3 as p,di as _,d4 as y,d2 as b,e4 as w,e5 as D,e6 as C,dM as v,j as T,d7 as I,d9 as S,d8 as M}from"./card-e5d55e5b.js";import{C as F}from"./engine-86b0096c.js";import{C as $,G as z,g as N}from"./engine-generic-93cdbee6.js";import{a as E,V as R}from"./media-c9012082.js";import{s as Y,e as x}from"./startOfHour-34edc6a8.js";function H(t){return e(1e3*t)}const j=n.object({camera:n.string(),end_time:n.number().nullable(),false_positive:n.boolean().nullable(),has_clip:n.boolean(),has_snapshot:n.boolean(),id:n.string(),label:n.string(),sub_label:n.string().nullable(),start_time:n.number(),top_score:n.number().nullable(),zones:n.string().array(),retain_indefinitely:n.boolean().optional()}).array(),Z=n.object({hour:n.preprocess((e=>Number(e)),n.number().min(0).max(23)),duration:n.number().min(0),events:n.number().min(0)}),q=n.object({day:n.preprocess((e=>"string"==typeof e?a(e):e),n.date()),events:n.number(),hours:Z.array()}).array(),U=n.object({start_time:n.number(),end_time:n.number(),id:n.string()}).array(),W=n.object({success:n.boolean(),message:n.string()}),Q=n.object({camera:n.string(),day:n.string(),label:n.string(),sub_label:n.string().nullable(),zones:n.string().array()}).array(),P=n.object({name:n.string().optional(),features:n.string().array().optional(),presets:n.string().array().optional()}),k=n.object({camera:n.string(),snapshot:n.object({frame_time:n.number()}).nullable(),has_clip:n.boolean(),has_snapshot:n.boolean(),label:n.string(),current_zones:n.string().array()}),A=n.object({before:k,after:k,type:n.enum(["new","update","end"])});const O=async(e,t)=>await r(e,j,{type:"frigate/events/get",...t},!0),L=e=>"birdseye"===e.frigate.camera_name;class V extends ${constructor(e,t,n){super(e,t,n),this._frigateEventHandler=e=>{const t=!e.before.has_snapshot&&e.after.has_snapshot||e.before.snapshot?.frame_time!==e.after.snapshot?.frame_time,n=!e.before.has_clip&&e.after.has_clip,a=this.getConfig();if(a.frigate.zones?.length&&!a.frigate.zones.some((t=>e.after.current_zones.includes(t)))||a.frigate.labels?.length&&!a.frigate.labels.includes(e.after.label))return;const r=a.triggers.events;(r.includes("events")||r.includes("snapshots")&&t||r.includes("clips")&&n)&&this._eventCallback?.({fidelity:"high",cameraID:this.getID(),type:e.type,clip:n&&r.includes("clips"),snapshot:t&&r.includes("snapshots")})}}async initialize(e){return await this._initializeConfig(e.hass,e.entityRegistryManager),await this._initializeCapabilities(e.hass),await this._subscribeToEvents(e.hass,e.frigateEventWatcher),await super.initialize(e)}async _initializeConfig(e,n){const a=this.getConfig(),r=!!a.frigate?.camera_name,i=a.triggers.motion||a.triggers.occupancy;let g=null;const l=o(a);if(l&&(!r||i)&&(g=await n.getEntity(e,l),!g))throw new c(s("error.no_camera_entity"),a);if(g&&!r){const e=this._getFrigateCameraNameFromEntity(g);e&&(this._config.frigate.camera_name=e)}if(i){const r=await n.getMatchingEntities(e,(e=>e.config_entry_id===g?.config_entry_id&&!e.disabled_by&&e.entity_id.startsWith("binary_sensor.")));if(a.triggers.motion){const e=this._getMotionSensor(a,[...r.values()]);e&&a.triggers.entities.push(e)}if(a.triggers.occupancy){const e=this._getOccupancySensor(a,[...r.values()]);e&&a.triggers.entities.push(...e)}a.triggers.entities=(u=a.triggers.entities)&&u.length?t(u):[]}var u}async _initializeCapabilities(e){const t=this.getConfig(),n=g(this.getConfig()),a=await this._getPTZCapabilities(e,t),r=n||a?{...a,...n}:null,i=L(t);this._capabilities=new l({"favorite-events":!i,"favorite-recordings":!1,seek:!i,clips:!i,snapshots:!i,recordings:!i,live:!0,menu:!0,substream:!0,...r&&{ptz:r}},{disable:t.capabilities?.disable,disableExcept:t.capabilities?.disable_except})}_getFrigateCameraNameFromEntity(e){if("frigate"===e.platform&&e.unique_id&&"string"==typeof e.unique_id){const t=e.unique_id.match(/:camera:(?<camera>[^:]+)$/);if(t&&t.groups)return t.groups.camera}return null}async _getPTZCapabilities(e,t){if(!t.frigate.came
|
|||
|
/* istanbul ignore next -- exercising the matcher is not possible when the
|
|||
|
test uses an event watcher -- @preserve */const a={instanceID:n.frigate.client_id,callback:e=>this._frigateEventHandler(e),matcher:e=>e.after.camera===n.frigate.camera_name};await t.subscribe(e,a),this._onDestroy((()=>t.unsubscribe(a)))}}class G{constructor(){this._requests=[],this._unsubscribeCallback={}}async subscribe(e,t){const n=!this._hasSubscribers(t.instanceID);this._requests.push(t),n&&(this._unsubscribeCallback[t.instanceID]=await e.connection.subscribeMessage((e=>this._receiveHandler(t.instanceID,e)),{type:"frigate/events/subscribe",instance_id:t.instanceID}))}async unsubscribe(e){this._requests=this._requests.filter((t=>t!==e)),this._hasSubscribers(e.instanceID)||(await this._unsubscribeCallback[e.instanceID](),delete this._unsubscribeCallback[e.instanceID])}_hasSubscribers(e){return!!this._requests.filter((t=>t.instanceID===e)).length}_receiveHandler(e,t){let n;try{n=JSON.parse(t)}catch(e){return void console.warn("Received non-JSON payload as Frigate event",t)}const a=A.safeParse(n);if(a.success)for(const t of this._requests)t.instanceID!==e||t.matcher&&!t.matcher(a.data)||t.callback(a.data);else console.warn("Received malformed Frigate event from Home Assistant",t)}}function J(e,t){const n=function(e){if(!B[e]){const t=new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:"America/New_York",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(new Date("2014-06-25T04:00:00.123Z")),n="06/25/2014, 00:00:00"===t||"06/25/2014 00:00:00"===t;B[e]=n?new Intl.DateTimeFormat("en-US",{hourCycle:"h23",timeZone:e,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}):new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:e,year:"numeric",month:"numeric",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})}return B[e]}(t);return"formatToParts"in n?function(e,t){try{const n=e.formatToParts(t),a=[];for(let e=0;e<n.length;e++){const t=X[n[e].type];void 0!==t&&(a[t]=parseInt(n[e].value,10))}return a}catch(e){if(e instanceof RangeError)return[NaN];throw e}}(n,e):function(e,t){const n=e.format(t),a=/(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(n);return[parseInt(a[3],10),parseInt(a[1],10),parseInt(a[2],10),parseInt(a[4],10),parseInt(a[5],10),parseInt(a[6],10)]}(n,e)}const X={year:0,month:1,day:2,hour:3,minute:4,second:5};const B={};function K(e,t,n,a,r,i,s){const o=new Date(0);return o.setUTCFullYear(e,t,n),o.setUTCHours(a,r,i,s),o}const ee=36e5,te=6e4,ne={timezone:/([Z+-].*)$/,timezoneZ:/^(Z)$/,timezoneHH:/^([+-]\d{2})$/,timezoneHHMM:/^([+-])(\d{2}):?(\d{2})$/};function ae(e,t,n){if(!e)return 0;let a,r,i=ne.timezoneZ.exec(e);if(i)return 0;if(i=ne.timezoneHH.exec(e),i)return a=parseInt(i[1],10),ie(a)?-a*ee:NaN;if(i=ne.timezoneHHMM.exec(e),i){a=parseInt(i[2],10);const e=parseInt(i[3],10);return ie(a,e)?(r=Math.abs(a)*ee+e*te,"+"===i[1]?-r:r):NaN}if(function(e){if(se[e])return!0;try{return new Intl.DateTimeFormat(void 0,{timeZone:e}),se[e]=!0,!0}catch(e){return!1}}(e)){t=new Date(t||Date.now());const a=n?t:function(e){return K(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())}(t),r=re(a,e),i=n?r:function(e,t,n){const a=e.getTime();let r=a-t;const i=re(new Date(r),n);if(t===i)return t;r-=i-t;const s=re(new Date(r),n);if(i===s)return i;return Math.max(i,s)}(t,r,e);return-i}return NaN}function re(e,t){const n=J(e,t),a=K(n[0],n[1]-1,n[2],n[3]%24,n[4],n[5],0).getTime();let r=e.getTime();const i=r%1e3;return r-=i>=0?i:1e3+i,a-r}function ie(e,t){return-23<=e&&e<=23&&(null==t||0<=t&&t<=59)}const se={};function oe(e){const t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return t.setUTCFullYear(e.getFullYear()),+e-+t}const ce=36e5,ge=6e4,le=2,ue={dateTimePattern:/^([0-9W+-]+)(T| )(.*)/,datePattern:/^([0-9W+-]+)(.*)/,plainTime:/:/,YY:/^(\d{2})$/,YYY:[/^([+-]\d{2})$/,/^([+-]\d{3})$/,/^([+-]\d{4})$/],YYYY:/^(\d{4})/,YYYYY:[/^([+-]\d{4})/,/^([+-]\d{5})/,/^([+-]\d{6})
|