matterbridge-open-tuya 0.1.0 → 0.2.1
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/CHANGELOG.md +12 -0
- package/README.md +25 -19
- package/apps/frontend/build/app.js +25 -3
- package/apps/frontend/build/app.js.map +4 -4
- package/dist/accessory/endpoints.js +33 -2
- package/dist/accessory/layout.js +1 -0
- package/dist/accessory/lightControl.js +74 -0
- package/dist/accessory/matterState.js +48 -2
- package/dist/accessory/tuyaAccessory.js +70 -8
- package/dist/features.js +58 -4
- package/dist/lightState.js +12 -0
- package/dist/mapping.js +77 -0
- package/npm-shrinkwrap.json +29 -29
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.2.1] - 2026-11-26
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- [devices]: Set the colour of a light reached through the Smart Life cloud, with open-tuya 0.3.2: the plugin read no colour from such a light, and each colour a Matter app set failed with an error in the log. A light reached on your network was not affected.
|
|
12
|
+
|
|
13
|
+
## [0.2.0] - 2026-11-26
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- [devices]: Control Tuya lights and dimmers from Matter: each light of a catalog entry, and each channel of a dimmer, is an On/Off, Dimmable, Color Temperature or Extended Color Light, with its brightness, the colour temperature of its white, and its colour as a hue and a saturation or as x and y. A light that shows only colours takes a colour temperature as the colour nearest to it, and a light with a white of no colour temperature turns to its white.
|
|
18
|
+
|
|
7
19
|
## [0.1.0] - 2026-11-01
|
|
8
20
|
|
|
9
21
|
### Added
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ It is a [Matterbridge](https://matterbridge.io) plugin built on [open-tuya](http
|
|
|
19
19
|
- **It finds your devices for you.** Sign in once in the setup page, by scanning a QR code with the Smart Life app or with a cloud project of the Tuya developer platform, and it lists every device of your account, with whether it can control each one. There is no local key, device ID or configuration file to look up: see [Guided setup](#guided-setup).
|
|
20
20
|
- **It talks to your devices on your network.** Each device is reached on the local network first, with the local key the cloud gives for it, which answers quicker and keeps working while the Tuya cloud or the internet is down, and through the Tuya cloud when it does not answer there: see [Connection](#connection).
|
|
21
21
|
- **It reaches the devices behind a gateway.** A Zigbee or Bluetooth device behind a Tuya gateway is reached through the gateway on your network, and through the cloud otherwise.
|
|
22
|
-
- **It offers only what your device can do.** The plugin reads what each device does from its catalog entry: each outlet of a power strip, the power and the energy of a plug that measures them, the temperature, the humidity, the light, the motion, the contact or the water leak of a sensor, its battery, and settings such as its child lock or the light of its buttons.
|
|
22
|
+
- **It offers only what your device can do.** The plugin reads what each device does from its catalog entry: the brightness, the colour temperature and the colour of a light, each channel of a dimmer, each outlet of a power strip, the power and the energy of a plug that measures them, the temperature, the humidity, the light, the motion, the contact or the water leak of a sensor, its battery, and settings such as its child lock or the light of its buttons.
|
|
23
23
|
- **It says when a device stops answering.** After two reads in a row fail, as they do while the Tuya cloud lists a device reached through it as offline, your Matter app shows the device as unreachable, and it comes back by itself as soon as the device answers again.
|
|
24
24
|
- **Almost nothing needs a restart.** Sign in, add, rename, reconnect and remove devices while Matterbridge keeps running. Only a change of how a device appears in Matter waits for the next restart, which the setup page and Matterbridge ask for.
|
|
25
25
|
|
|
@@ -54,44 +54,47 @@ Open the plugin frontend from the plugin's row on the Matterbridge home page. Th
|
|
|
54
54
|
|
|
55
55
|
Then it walks through three steps:
|
|
56
56
|
|
|
57
|
-
1. **Find.** The page lists the devices of your account and marks those already set up. It says why it cannot control one: a kind of device it does not control yet, such as a
|
|
57
|
+
1. **Find.** The page lists the devices of your account and marks those already set up. It says why it cannot control one: a kind of device it does not control yet, such as a fan or a thermostat, or a gateway, whose devices are listed on their own. A device whose product the catalog does not list can still be picked: the next step reads what the Tuya cloud says of it.
|
|
58
58
|
2. **Connect.** For each device you picked, the plugin reads it, on your network first and through the Tuya cloud otherwise, and finds what its data points do: from the catalog entry of its product, else from the Tuya cloud's model of a motion, presence, contact, water leak or temperature and humidity sensor, which names each data point by Tuya's standard codes, such as `temp_current`, else from the catalog entry that names most of the data points it reports. The model comes before that last match, which cannot tell apart two devices that report the same data points, such as a motion sensor and a water leak sensor.
|
|
59
|
-
3. **Options.** The name the device gets in Matter, starting from its name in the Smart Life app, which of its outlets, its sensors, its meter and its setting switches appear in Matter, and whether they are one device or several. Last, whether it is reached on your network first or through the Tuya cloud only, and, only for a network the plugin does not hear it on, a host and a protocol version, which most devices leave empty: see [Connection](#connection).
|
|
59
|
+
3. **Options.** The name the device gets in Matter, starting from its name in the Smart Life app, which of its lights, its outlets, its sensors, its meter and its setting switches appear in Matter, and whether they are one device or several. Last, whether it is reached on your network first or through the Tuya cloud only, and, only for a network the plugin does not hear it on, a host and a protocol version, which most devices leave empty: see [Connection](#connection).
|
|
60
60
|
|
|
61
61
|
Afterwards the same page lists your devices with their status: online on your network or through the Tuya cloud, connecting, not answering, or not started, and what they last reported. From there you can add more, change the options of one, reconnect one that stopped answering, remove one, switch to another account, sign in again when the Tuya cloud no longer accepts the sign in, or sign out. Matterbridge's own list of devices shows a device added or removed here once you reload its page, named after its device ID, such as `Tuya bf1234567890abcdefgh`: the name you give it is what the Matter apps show.
|
|
62
62
|
|
|
63
63
|
## How a device appears in Matter
|
|
64
64
|
|
|
65
|
-
The plugin controls the devices whose catalog entry is a switch, a plug, a power strip or a sensor, with the lights of their buttons or their display. A
|
|
65
|
+
The plugin controls the devices whose catalog entry is a light, a dimmer, a switch, a plug, a power strip or a sensor, with the lights of their buttons or their display. A fan, a ceiling fan with a light, a thermostat, a cover, a lock, a vacuum and the other kinds of the catalog are not controlled yet.
|
|
66
66
|
|
|
67
|
-
| In Matter | From the device
|
|
68
|
-
| ---------------------------------- |
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
|
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
|
77
|
-
|
|
|
78
|
-
|
|
|
67
|
+
| In Matter | From the device |
|
|
68
|
+
| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
69
|
+
| Light | Each light, or each channel of a dimmer: an On/Off Light, a Dimmable Light with its brightness, a Color Temperature Light with the colour temperature of its white, or an Extended Color Light with its colour |
|
|
70
|
+
| Outlet | Each switch of its main function: the plug, each outlet of a power strip, each gang of a wall switch, its USB ports |
|
|
71
|
+
| Electrical power and energy | The power, the voltage, the current and the energy used so far, on the first outlet of a device that measures them |
|
|
72
|
+
| Temperature sensor | Its temperature, in °C or °F |
|
|
73
|
+
| Humidity sensor | Its relative humidity |
|
|
74
|
+
| Light sensor | Its illuminance |
|
|
75
|
+
| Occupancy sensor | The motion or the presence it detects |
|
|
76
|
+
| Contact sensor | Whether its door or window is open |
|
|
77
|
+
| Water leak detector | Whether it detects water |
|
|
78
|
+
| Battery | The charge of its battery, as the power source of the device |
|
|
79
|
+
| Outlet, for a setting, when chosen | Each on/off setting, such as the child lock or the light of its buttons or its display |
|
|
79
80
|
|
|
80
|
-
The first
|
|
81
|
+
The first light, else the first outlet, else the first sensor, is the device itself: it is always there. Every other light, outlet and sensor, and the meter, can be left out in the options. A setting switch is left out unless you choose it.
|
|
81
82
|
|
|
82
83
|
### How it is built in Matter
|
|
83
84
|
|
|
84
|
-
Matter describes a device as endpoints. Each endpoint has one or more device types, which say what it is, and clusters, which hold its attributes and commands. Each device is one device: an endpoint for its first outlet or its first sensor, with every other outlet, sensor or setting switch as a part of it, on an endpoint of its own:
|
|
85
|
+
Matter describes a device as endpoints. Each endpoint has one or more device types, which say what it is, and clusters, which hold its attributes and commands. Each device is one device: an endpoint for its first light, its first outlet or its first sensor, with every other light, outlet, sensor or setting switch as a part of it, on an endpoint of its own:
|
|
85
86
|
|
|
86
87
|
```mermaid
|
|
87
88
|
flowchart TD
|
|
88
89
|
bridge["Matterbridge<br/>Aggregator"]
|
|
89
90
|
subgraph device["One device in a Matter app"]
|
|
90
|
-
main["<b>Desk Plug</b><br/>On/Off Plug-in Unit,
|
|
91
|
+
main["<b>Desk Plug</b><br/>The light of a device with one, else On/Off Plug-in Unit, else the sensor, Bridged Node, Power Source<br/>On/Off, and Electrical Sensor with Power Topology, Electrical Power and Electrical Energy Measurement on a device that measures them<br/>Power Source wired, or with the charge of its battery"]
|
|
91
92
|
outlets["On/Off Plug-in Unit, one for each other outlet and each setting switch<br/>tagged 1 Outlet 2, 2 Outlet 3 and so on<br/>On/Off"]
|
|
92
93
|
sensors["Temperature, Humidity, Light, Occupancy, Contact Sensor or Water Leak Detector, one for each other reading<br/>Temperature, Relative Humidity, Illuminance Measurement, Occupancy Sensing or Boolean State"]
|
|
93
94
|
end
|
|
95
|
+
lights["On/Off, Dimmable, Color Temperature or Extended Color Light, one for each other light<br/>On/Off, Level Control, and Color Control with its colour temperature, its hue and saturation and its x and y"]
|
|
94
96
|
bridge --> main
|
|
97
|
+
main -.-> lights
|
|
95
98
|
main -.-> outlets
|
|
96
99
|
main -.-> sensors
|
|
97
100
|
```
|
|
@@ -134,6 +137,9 @@ The account and the devices are set up in the setup page alone. The Matterbridge
|
|
|
134
137
|
|
|
135
138
|
- **The Smart Life session serves one program.** Two programs signed in with the same session, such as this plugin and Home Assistant with a copy of its configuration, end it for both: sign each in by a QR code of its own.
|
|
136
139
|
- **A device on protocol 3.1 reads under a wrong local key.** A command that times out on one is the sign that its key is wrong: read the device list again from the setup page.
|
|
140
|
+
- **A light shows its white and its colour, not its scenes.** A light in a scene or a music mode shows in Matter as its white, and a Matter app that sets a colour or a colour temperature turns it back to its colour or its white. The timer, the scenes and the other settings of a light are not in Matter.
|
|
141
|
+
- **A light whose product the catalog does not list is matched by its data points.** The Tuya cloud's model names only sensors, so such a light takes the catalog entry that names most of the data points it reports, which most bulbs share.
|
|
142
|
+
- **A light shows no meter.** A device with a light and an outlet that measures power shows the light as the device itself, without the meter.
|
|
137
143
|
- **The meter shows the first phase.** A device that measures three phases shows the readings the catalog gives for the device as a whole, or none.
|
|
138
144
|
- **A device that refuses a read.** Some 3.2 and 3.3 devices answer every read with an error. open-tuya can read them by writing null to their data points, which this plugin does not do, since a null write changes some devices: they are reached through the cloud instead.
|
|
139
145
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
`}return a%2&&d>0?
|
|
3
|
-
`}return q.substring(0,q.length-1)},m.renderTo2dContext=function(d,l){l=l||2;for(var a=m.getModuleCount(),p=0;p<a;p++)for(var h=0;h<a;h++)d.fillStyle=m.isDark(p,h)?"black":"white",d.fillRect(p*l,h*l,l,l)},m};e.stringToBytesFuncs={default:function(C){for(var T=[],b=0;b<C.length;b+=1){var x=C.charCodeAt(b);T.push(x&255)}return T}},e.stringToBytes=e.stringToBytesFuncs.default,e.createStringToBytes=function(C,T){var b=(function(){for(var c=bt(C),y=function(){var $=c.read();if($==-1)throw"eof";return $},s=0,n={};;){var w=c.read();if(w==-1)break;var f=y(),m=y(),A=y(),E=String.fromCharCode(w<<8|f),N=m<<8|A;n[E]=N,s+=1}if(s!=T)throw s+" != "+T;return n})(),x=63;return function(c){for(var y=[],s=0;s<c.length;s+=1){var n=c.charCodeAt(s);if(n<128)y.push(n);else{var w=b[c.charAt(s)];typeof w=="number"?(w&255)==w?y.push(w):(y.push(w>>>8),y.push(w&255)):y.push(x)}}return y}};var t={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},o={L:1,M:0,Q:3,H:2},u={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},g=(function(){var C=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],T=1335,b=7973,x=21522,c={},y=function(s){for(var n=0;s!=0;)n+=1,s>>>=1;return n};return c.getBCHTypeInfo=function(s){for(var n=s<<10;y(n)-y(T)>=0;)n^=T<<y(n)-y(T);return(s<<10|n)^x},c.getBCHTypeNumber=function(s){for(var n=s<<12;y(n)-y(b)>=0;)n^=b<<y(n)-y(b);return s<<12|n},c.getPatternPosition=function(s){return C[s-1]},c.getMaskFunction=function(s){switch(s){case u.PATTERN000:return function(n,w){return(n+w)%2==0};case u.PATTERN001:return function(n,w){return n%2==0};case u.PATTERN010:return function(n,w){return w%3==0};case u.PATTERN011:return function(n,w){return(n+w)%3==0};case u.PATTERN100:return function(n,w){return(Math.floor(n/2)+Math.floor(w/3))%2==0};case u.PATTERN101:return function(n,w){return n*w%2+n*w%3==0};case u.PATTERN110:return function(n,w){return(n*w%2+n*w%3)%2==0};case u.PATTERN111:return function(n,w){return(n*w%3+(n+w)%2)%2==0};default:throw"bad maskPattern:"+s}},c.getErrorCorrectPolynomial=function(s){for(var n=k([1],0),w=0;w<s;w+=1)n=n.multiply(k([1,v.gexp(w)],0));return n},c.getLengthInBits=function(s,n){if(1<=n&&n<10)switch(s){case t.MODE_NUMBER:return 10;case t.MODE_ALPHA_NUM:return 9;case t.MODE_8BIT_BYTE:return 8;case t.MODE_KANJI:return 8;default:throw"mode:"+s}else if(n<27)switch(s){case t.MODE_NUMBER:return 12;case t.MODE_ALPHA_NUM:return 11;case t.MODE_8BIT_BYTE:return 16;case t.MODE_KANJI:return 10;default:throw"mode:"+s}else if(n<41)switch(s){case t.MODE_NUMBER:return 14;case t.MODE_ALPHA_NUM:return 13;case t.MODE_8BIT_BYTE:return 16;case t.MODE_KANJI:return 12;default:throw"mode:"+s}else throw"type:"+n},c.getLostPoint=function(s){for(var n=s.getModuleCount(),w=0,f=0;f<n;f+=1)for(var m=0;m<n;m+=1){for(var A=0,E=s.isDark(f,m),N=-1;N<=1;N+=1)if(!(f+N<0||n<=f+N))for(var $=-1;$<=1;$+=1)m+$<0||n<=m+$||N==0&&$==0||E==s.isDark(f+N,m+$)&&(A+=1);A>5&&(w+=3+A-5)}for(var f=0;f<n-1;f+=1)for(var m=0;m<n-1;m+=1){var H=0;s.isDark(f,m)&&(H+=1),s.isDark(f+1,m)&&(H+=1),s.isDark(f,m+1)&&(H+=1),s.isDark(f+1,m+1)&&(H+=1),(H==0||H==4)&&(w+=3)}for(var f=0;f<n;f+=1)for(var m=0;m<n-6;m+=1)s.isDark(f,m)&&!s.isDark(f,m+1)&&s.isDark(f,m+2)&&s.isDark(f,m+3)&&s.isDark(f,m+4)&&!s.isDark(f,m+5)&&s.isDark(f,m+6)&&(w+=40);for(var m=0;m<n;m+=1)for(var f=0;f<n-6;f+=1)s.isDark(f,m)&&!s.isDark(f+1,m)&&s.isDark(f+2,m)&&s.isDark(f+3,m)&&s.isDark(f+4,m)&&!s.isDark(f+5,m)&&s.isDark(f+6,m)&&(w+=40);for(var V=0,m=0;m<n;m+=1)for(var f=0;f<n;f+=1)s.isDark(f,m)&&(V+=1);var W=Math.abs(100*V/n/n-50)/5;return w+=W*10,w},c})(),v=(function(){for(var C=new Array(256),T=new Array(256),b=0;b<8;b+=1)C[b]=1<<b;for(var b=8;b<256;b+=1)C[b]=C[b-4]^C[b-5]^C[b-6]^C[b-8];for(var b=0;b<255;b+=1)T[C[b]]=b;var x={};return x.glog=function(c){if(c<1)throw"glog("+c+")";return T[c]},x.gexp=function(c){for(;c<0;)c+=255;for(;c>=256;)c-=255;return C[c]},x})();function k(C,T){if(typeof C.length>"u")throw C.length+"/"+T;var b=(function(){for(var c=0;c<C.length&&C[c]==0;)c+=1;for(var y=new Array(C.length-c+T),s=0;s<C.length-c;s+=1)y[s]=C[s+c];return y})(),x={};return x.getAt=function(c){return b[c]},x.getLength=function(){return b.length},x.multiply=function(c){for(var y=new Array(x.getLength()+c.getLength()-1),s=0;s<x.getLength();s+=1)for(var n=0;n<c.getLength();n+=1)y[s+n]^=v.gexp(v.glog(x.getAt(s))+v.glog(c.getAt(n)));return k(y,0)},x.mod=function(c){if(x.getLength()-c.getLength()<0)return x;for(var y=v.glog(x.getAt(0))-v.glog(c.getAt(0)),s=new Array(x.getLength()),n=0;n<x.getLength();n+=1)s[n]=x.getAt(n);for(var n=0;n<c.getLength();n+=1)s[n]^=v.gexp(v.glog(c.getAt(n))+y);return k(s,0).mod(c)},x}var _=(function(){var C=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],T=function(c,y){var s={};return s.totalCount=c,s.dataCount=y,s},b={},x=function(c,y){switch(y){case o.L:return C[(c-1)*4+0];case o.M:return C[(c-1)*4+1];case o.Q:return C[(c-1)*4+2];case o.H:return C[(c-1)*4+3];default:return}};return b.getRSBlocks=function(c,y){var s=x(c,y);if(typeof s>"u")throw"bad rs block @ typeNumber:"+c+"/errorCorrectionLevel:"+y;for(var n=s.length/3,w=[],f=0;f<n;f+=1)for(var m=s[f*3+0],A=s[f*3+1],E=s[f*3+2],N=0;N<m;N+=1)w.push(T(A,E));return w},b})(),P=function(){var C=[],T=0,b={};return b.getBuffer=function(){return C},b.getAt=function(x){var c=Math.floor(x/8);return(C[c]>>>7-x%8&1)==1},b.put=function(x,c){for(var y=0;y<c;y+=1)b.putBit((x>>>c-y-1&1)==1)},b.getLengthInBits=function(){return T},b.putBit=function(x){var c=Math.floor(T/8);C.length<=c&&C.push(0),x&&(C[c]|=128>>>T%8),T+=1},b},ie=function(C){var T=t.MODE_NUMBER,b=C,x={};x.getMode=function(){return T},x.getLength=function(s){return b.length},x.write=function(s){for(var n=b,w=0;w+2<n.length;)s.put(c(n.substring(w,w+3)),10),w+=3;w<n.length&&(n.length-w==1?s.put(c(n.substring(w,w+1)),4):n.length-w==2&&s.put(c(n.substring(w,w+2)),7))};var c=function(s){for(var n=0,w=0;w<s.length;w+=1)n=n*10+y(s.charAt(w));return n},y=function(s){if("0"<=s&&s<="9")return s.charCodeAt(0)-48;throw"illegal char :"+s};return x},F=function(C){var T=t.MODE_ALPHA_NUM,b=C,x={};x.getMode=function(){return T},x.getLength=function(y){return b.length},x.write=function(y){for(var s=b,n=0;n+1<s.length;)y.put(c(s.charAt(n))*45+c(s.charAt(n+1)),11),n+=2;n<s.length&&y.put(c(s.charAt(n)),6)};var c=function(y){if("0"<=y&&y<="9")return y.charCodeAt(0)-48;if("A"<=y&&y<="Z")return y.charCodeAt(0)-65+10;switch(y){case" ":return 36;case"$":return 37;case"%":return 38;case"*":return 39;case"+":return 40;case"-":return 41;case".":return 42;case"/":return 43;case":":return 44;default:throw"illegal char :"+y}};return x},mt=function(C){var T=t.MODE_8BIT_BYTE,b=C,x=e.stringToBytes(C),c={};return c.getMode=function(){return T},c.getLength=function(y){return x.length},c.write=function(y){for(var s=0;s<x.length;s+=1)y.put(x[s],8)},c},yt=function(C){var T=t.MODE_KANJI,b=C,x=e.stringToBytesFuncs.SJIS;if(!x)throw"sjis not supported.";(function(s,n){var w=x(s);if(w.length!=2||(w[0]<<8|w[1])!=n)throw"sjis not supported."})("\u53CB",38726);var c=x(C),y={};return y.getMode=function(){return T},y.getLength=function(s){return~~(c.length/2)},y.write=function(s){for(var n=c,w=0;w+1<n.length;){var f=(255&n[w])<<8|255&n[w+1];if(33088<=f&&f<=40956)f-=33088;else if(57408<=f&&f<=60351)f-=49472;else throw"illegal char at "+(w+1)+"/"+f;f=(f>>>8&255)*192+(f&255),s.put(f,13),w+=2}if(w<n.length)throw"illegal char at "+(w+1)},y},Ne=function(){var C=[],T={};return T.writeByte=function(b){C.push(b&255)},T.writeShort=function(b){T.writeByte(b),T.writeByte(b>>>8)},T.writeBytes=function(b,x,c){x=x||0,c=c||b.length;for(var y=0;y<c;y+=1)T.writeByte(b[y+x])},T.writeString=function(b){for(var x=0;x<b.length;x+=1)T.writeByte(b.charCodeAt(x))},T.toByteArray=function(){return C},T.toString=function(){var b="";b+="[";for(var x=0;x<C.length;x+=1)x>0&&(b+=","),b+=C[x];return b+="]",b},T},wt=function(){var C=0,T=0,b=0,x="",c={},y=function(n){x+=String.fromCharCode(s(n&63))},s=function(n){if(!(n<0)){if(n<26)return 65+n;if(n<52)return 97+(n-26);if(n<62)return 48+(n-52);if(n==62)return 43;if(n==63)return 47}throw"n:"+n};return c.writeByte=function(n){for(C=C<<8|n&255,T+=8,b+=1;T>=6;)y(C>>>T-6),T-=6},c.flush=function(){if(T>0&&(y(C<<6-T),C=0,T=0),b%3!=0)for(var n=3-b%3,w=0;w<n;w+=1)x+="="},c.toString=function(){return x},c},bt=function(C){var T=C,b=0,x=0,c=0,y={};y.read=function(){for(;c<8;){if(b>=T.length){if(c==0)return-1;throw"unexpected end of file./"+c}var n=T.charAt(b);if(b+=1,n=="=")return c=0,-1;if(n.match(/^\s$/))continue;x=x<<6|s(n.charCodeAt(0)),c+=6}var w=x>>>c-8&255;return c-=8,w};var s=function(n){if(65<=n&&n<=90)return n-65;if(97<=n&&n<=122)return n-97+26;if(48<=n&&n<=57)return n-48+52;if(n==43)return 62;if(n==47)return 63;throw"c:"+n};return y},xt=function(C,T){var b=C,x=T,c=new Array(C*T),y={};y.setPixel=function(f,m,A){c[m*b+f]=A},y.write=function(f){f.writeString("GIF87a"),f.writeShort(b),f.writeShort(x),f.writeByte(128),f.writeByte(0),f.writeByte(0),f.writeByte(0),f.writeByte(0),f.writeByte(0),f.writeByte(255),f.writeByte(255),f.writeByte(255),f.writeString(","),f.writeShort(0),f.writeShort(0),f.writeShort(b),f.writeShort(x),f.writeByte(0);var m=2,A=n(m);f.writeByte(m);for(var E=0;A.length-E>255;)f.writeByte(255),f.writeBytes(A,E,255),E+=255;f.writeByte(A.length-E),f.writeBytes(A,E,A.length-E),f.writeByte(0),f.writeString(";")};var s=function(f){var m=f,A=0,E=0,N={};return N.write=function($,H){if($>>>H)throw"length over";for(;A+H>=8;)m.writeByte(255&($<<A|E)),H-=8-A,$>>>=8-A,E=0,A=0;E=$<<A|E,A=A+H},N.flush=function(){A>0&&m.writeByte(E)},N},n=function(f){for(var m=1<<f,A=(1<<f)+1,E=f+1,N=w(),$=0;$<m;$+=1)N.add(String.fromCharCode($));N.add(String.fromCharCode(m)),N.add(String.fromCharCode(A));var H=Ne(),V=s(H);V.write(m,E);var W=0,G=String.fromCharCode(c[W]);for(W+=1;W<c.length;){var X=String.fromCharCode(c[W]);W+=1,N.contains(G+X)?G=G+X:(V.write(N.indexOf(G),E),N.size()<4095&&(N.size()==1<<E&&(E+=1),N.add(G+X)),G=X)}return V.write(N.indexOf(G),E),V.write(A,E),V.flush(),H.toByteArray()},w=function(){var f={},m=0,A={};return A.add=function(E){if(A.contains(E))throw"dup key:"+E;f[E]=m,m+=1},A.size=function(){return m},A.indexOf=function(E){return f[E]},A.contains=function(E){return typeof f[E]<"u"},A};return y},St=function(C,T,b){for(var x=xt(C,T),c=0;c<T;c+=1)for(var y=0;y<C;y+=1)x.setPixel(y,c,b(y,c));var s=Ne();x.write(s);for(var n=wt(),w=s.toByteArray(),f=0;f<w.length;f+=1)n.writeByte(w[f]);return n.flush(),"data:image/gif;base64,"+n};return e})();(function(){ut.stringToBytesFuncs["UTF-8"]=function(e){function t(o){for(var u=[],g=0;g<o.length;g++){var v=o.charCodeAt(g);v<128?u.push(v):v<2048?u.push(192|v>>6,128|v&63):v<55296||v>=57344?u.push(224|v>>12,128|v>>6&63,128|v&63):(g++,v=65536+((v&1023)<<10|o.charCodeAt(g)&1023),u.push(240|v>>18,128|v>>12&63,128|v>>6&63,128|v&63))}return u}return t(e)}})();(function(e){typeof define=="function"&&define.amd?define([],e):typeof ct=="object"&&(dt.exports=e())})(function(){return ut})});var se={cn:"China",us:"Western America","us-e":"Eastern America",eu:"Central Europe","eu-w":"Western Europe",in:"India",sg:"Singapore"},Fe=["3.1","3.2","3.3","3.4","3.5"],ae="meter";async function j(e,t){try{let[o,u]=e.split(" "),g={method:o};t!==void 0&&(g.headers={"Content-Type":"application/json"},g.body=JSON.stringify(t));let v=await fetch(new URL(`api/${u}`,document.baseURI),g);if(v.status===503)return{ok:!1,error:"The plugin is not running. Start it in Matterbridge, then reload this page."};let k=await v.json();return"ok"in k?k:{ok:!1,error:k.error??`The plugin answered with status ${v.status}`}}catch{return{ok:!1,error:"Matterbridge did not answer. Check that it is running, then try again."}}}var i={screen:"loading",setup:void 0,signIn:{method:"smartLife",userCode:"",accessId:"",dataCenter:"eu"},login:{status:"idle"},devices:[],selected:new Set,queue:[],saved:[],handled:[],isBusy:!1,busyText:"",error:"",info:"",confirmingRemoval:"",confirmingSignOut:!1};function J(){return i.queue[0]}function ee(e){return e.name===""?e.device.deviceId:e.name}function le(e,t){let o=t===void 0?"device":t;return e.cloudName===void 0?`${o} ${e.deviceId}`:`${o} ${e.deviceId}, named "${e.cloudName}" in the Smart Life app`}var Oe=32;function ke(e,t){if(!He(e)||!He(t))return JSON.stringify(e)===JSON.stringify(t);let o=Object.keys(e);return o.length===Object.keys(t).length&&o.every(u=>ke(e[u],t[u]))}function He(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function fe(e){return{hiddenFeatures:[...e.hiddenFeatures],addedFeatures:[...e.addedFeatures],isComposed:e.isComposed}}function ue(e){return(e.outlets[0]??e.sensors[0])?.id}function Ie(e,t){let o=ue(t),u=new Set([...t.outlets,...t.sensors].map(v=>v.id).filter(v=>v!==o));t.meter!==void 0&&t.outlets.length>0&&u.add("meter");let g=new Set(t.settingSwitches.map(v=>v.id));return{hiddenFeatures:e.hiddenFeatures.filter(v=>u.has(v)),addedFeatures:e.addedFeatures.filter(v=>g.has(v)),isComposed:e.isComposed}}function Nt(e,t){let o=e.trim().slice(0,Oe).trimEnd();if(o===""||!t.has(o))return o;for(let u=2;;u++){let g=` ${u}`,v=`${o.slice(0,Oe-g.length).trimEnd()}${g}`;if(!t.has(v))return v}}function je(e){let t=new Set((i.setup?.devices??[]).map(o=>o.name));return e.map(o=>{let u=Nt(o.name,t);return t.add(u),{device:{deviceId:o.deviceId,cloudName:o.name,productKey:o.productKey,category:o.category},name:u,host:"",version:"",isCloudOnly:!1,isNew:!0,hiddenFeatures:[],addedFeatures:[],isComposed:!1}})}function pe(e){return{device:{deviceId:e.deviceId,cloudName:e.cloudName,productKey:e.productKey,category:e.category},name:e.name,host:e.host??"",version:e.version??"",isCloudOnly:e.isCloudOnly??!1,isNew:!1,catalogFile:e.catalogFile,model:e.model,productName:e.productName,features:e.features,values:e.values,...fe(e)}}var De;function qe(e){De=e}function L(){let e=document.getElementById("app");if(e===null||De===void 0)return;let t=`${i.screen}:${J()?.device.deviceId??""}`,o=e.dataset.form===t,u=document.activeElement,g=u instanceof HTMLElement?u.id:"",v=u instanceof HTMLInputElement&&(u.type==="text"||u.type==="password")?{start:u.selectionStart,end:u.selectionEnd}:void 0,k=new Map;for(let P of e.querySelectorAll("input[type=text], input[type=email], input[type=password]"))P.id!==""&&k.set(P.id,P.value);if(e.replaceChildren(...De[i.screen]().filter(P=>P!==!1&&P!==null&&P!==void 0)),e.dataset.form=t,!o)return;for(let[P,ie]of k){let F=document.getElementById(P);F instanceof HTMLInputElement&&(F.value=ie)}if(g==="")return;let _=document.getElementById(g);_?.focus(),v!==void 0&&_ instanceof HTMLInputElement&&_.setSelectionRange(v.start,v.end)}async function Y(e,t){i.isBusy=!0,i.busyText=e,i.error="",i.info="",L();try{return await t()}finally{i.isBusy=!1,L()}}async function ge(){let e=await j("GET state");if(!e.ok){i.error=e.error,i.screen="home",L();return}if(Z(e.state),e.state.account===void 0&&e.state.devices.length===0){ne();return}if(e.state.account!==void 0&&e.state.devices.length===0&&!e.state.account.needsSignIn){await re();return}i.screen="home",L(),Bt()}async function Bt(){if(i.setup?.account===void 0)return;let e=await j("POST sync");!e.ok||JSON.stringify(e.state)===JSON.stringify(i.setup)||(Z(e.state),L())}var Pt=2e3,Le;function Z(e){i.setup=e,!(Le!==void 0||!e.devices.some(t=>t.status==="connecting"))&&(Le=window.setTimeout(()=>{Le=void 0,$t()},Pt))}async function $t(){let e=await j("GET state");if(!e.ok)return;let t=JSON.stringify(e.state)!==JSON.stringify(i.setup);Z(e.state),t&&i.screen==="home"&&L()}async function te(){let e=await j("GET state");e.ok&&Z(e.state)}function K(){ve(),i.queue=[],i.saved=[],i.handled=[],i.error="",i.info="",i.screen="home",te().then(L),L()}function ne(){let e=i.setup?.account;e?.type==="smartLife"&&(i.signIn={...i.signIn,method:"smartLife",userCode:e.userCode}),e?.type==="developer"&&(i.signIn={...i.signIn,method:"developer",accessId:e.accessId,dataCenter:e.dataCenter}),i.login={status:"idle"},i.error="",i.info="",i.screen="signIn",L()}var _t=2e3,he;function ve(){window.clearInterval(he),he=void 0}async function Qe(e){i.signIn.userCode=e,ve();let t=await Y("Asking the Smart Life cloud for a QR code\u2026",async()=>j("POST qr-code",{userCode:e}));if(!t.ok){i.error=t.error,L();return}i.login=t.login,L(),he=window.setInterval(()=>{Ft()},_t)}async function Ft(){let e=await j("GET qr-login");if(!e.ok||i.screen!=="signIn"||he===void 0)return;let{login:t}=e;t.status!=="waiting"&&(ve(),await Ot(t,e.state))}async function Ot(e,t){if(i.login=e,e.status!=="signedIn"){L();return}Z(t),await Ke(t)}async function Ke(e){i.login={status:"idle"},e.devices.length===0?await re():K()}async function Ue(){ve(),i.login={status:"idle"},await j("POST cancel-qr-code"),L()}async function Ve(e,t,o){i.signIn={...i.signIn,accessId:e,dataCenter:o};let u=await Y("Signing in to the Tuya developer platform\u2026",async()=>j("POST developer-login",{accessId:e,accessSecret:t,dataCenter:o}));if(!u.ok){i.error=u.error,L();return}Z(u.state),await Ke(u.state)}async function Je(){let e=await Y("Signing out\u2026",async()=>j("POST sign-out"));i.confirmingSignOut=!1,e.ok||(i.error=e.error),await te(),L()}async function re(){i.screen="find";let e=await Y("Reading the devices of your Tuya account\u2026",async()=>j("POST devices"));if(!e.ok){i.error=`The devices could not be read: ${e.error}`,L();return}await te(),i.devices=e.devices;for(let t of e.devices)!t.isConfigured&&t.support==="supported"&&i.selected.add(t.deviceId);L()}function me(e){i.queue=e,i.saved=[],i.handled=[],Me()}function We(e){i.queue=[pe(e)],i.saved=[],i.handled=[],i.error="",i.info="",i.screen="options",L()}async function Ge(e){let t=await Y(`Reconnecting ${e.name}\u2026`,async()=>j("POST reconnect",{deviceId:e.deviceId}));t.ok?Z(t.state):i.error=t.error,L()}async function Me(){let e=J();if(e===void 0){i.screen=i.saved.length>0?"done":"home",await te(),L();return}i.screen="connect",i.error="",i.info="",e.probe=void 0,L(),await Ae(e)}async function Ae(e){let t=await Y(`Connecting to ${ee(e)} on your network, and through the Tuya cloud\u2026`,async()=>j("POST probe",{deviceId:e.device.deviceId}));if(!t.ok){i.error=t.error,L();return}let{result:o}=t;e.probe=o,o.status==="signInRequired"&&await te(),o.status==="ready"&&o.features!==void 0&&(o.catalogFile!==void 0||o.model!==void 0)&&(e.features=o.features,e.values=o.values,e.productName=o.productName,(e.catalogFile!==void 0||e.model!==void 0)&&(e.catalogFile!==o.catalogFile||!ke(e.model,o.model))&&Object.assign(e,{hiddenFeatures:[],addedFeatures:[]}),e.catalogFile=o.catalogFile,e.model=o.model,Object.assign(e,Ie(fe(e),o.features)),i.screen="options"),L()}function Ye(){let e=i.queue.shift();e!==void 0&&i.handled.push({label:ee(e),isSaved:!1}),Me()}async function Ze(e){let t=e.name.trim(),o=Ht(e,t)||jt(e);if(o!==""){i.error=o,L();return}if(e.catalogFile===void 0&&e.model===void 0)return;let{device:u}=e,g=!e.isCloudOnly&&e.host!=="",v={deviceId:u.deviceId,name:t,productKey:u.productKey,catalogFile:e.catalogFile,model:e.model,category:u.category,...Ie(fe(e),e.features??{outlets:[],settingSwitches:[],sensors:[]}),host:g?e.host:void 0,version:g?e.version:void 0,isCloudOnly:e.isCloudOnly||void 0},k=await Y(`Saving ${t}\u2026`,async()=>j("POST device",{device:v}));if(!k.ok){i.error=k.error,L();return}Z(k.state),i.saved.push(t),i.handled.push({label:t,isSaved:!0}),i.queue.shift(),await Me()}function Ht(e,t){return t===""?"Give the device a name: it is the name it gets in Matter.":(i.setup?.devices??[]).some(u=>u.name===t&&u.deviceId!==e.device.deviceId)?`"${t}" is already the name of another device. Pick a different one.`:""}function jt(e){return e.isCloudOnly||e.host===""?"":/^[A-Za-z0-9](?:[A-Za-z0-9.-]{0,251}[A-Za-z0-9])?$/.test(e.host)?e.version===""?"Pick the protocol version the device speaks at that host, or leave the host empty.":"":`"${e.host}" is not a host name or an IPv4 address.`}var Ee="Matterbridge's own list of devices shows the change once you reload its page.",Xe="Restart Matterbridge to apply the new options in Matter: until then the device keeps its current endpoints.";async function ze(e){let t=await Y(`Removing ${e.name}\u2026`,async()=>j("POST remove-device",{deviceId:e.deviceId}));i.confirmingRemoval="",t.ok?i.info=`${e.name} is removed. ${Ee}`:i.error=t.error,await te(),L()}function r(e,t={},...o){let u=document.createElement(e);for(let[g,v]of Object.entries(t))v===void 0||v===!1||(g==="class"?u.className=String(v):g==="html"?u.innerHTML=String(v):g.startsWith("on")&&typeof v=="function"?u.addEventListener(g.slice(2),v):g in u?u[g]=v:u.setAttribute(g,String(v)));for(let g of o)g!==!1&&g!==null&&g!==void 0&&u.append(g);return u}function R(e,t,o="quiet",u=!1){return r("button",{type:"button",class:`button ${o}`,onclick:t,disabled:u||i.isBusy},e)}function U(){return i.isBusy?r("p",{class:"notice working",role:"status"},r("span",{class:"spinner"}),i.busyText):i.error!==""?r("p",{class:"notice problem",role:"alert"},i.error):i.info!==""?r("p",{class:"notice",role:"status"},i.info):null}function ye(){let e=J();if(e===void 0||!e.isNew||i.handled.length+i.queue.length<2)return null;let t=i.screen==="connect"?"Connecting":"Choosing options";return r("ol",{class:"units","aria-label":"Devices in this setup"},...i.handled.map(o=>r("li",{class:o.isSaved?"done":"skipped"},r("strong",{},o.label),r("span",{class:"meta"},o.isSaved?"Added":"Skipped"))),...i.queue.map((o,u)=>r("li",{class:u===0?"current":"ahead","aria-current":u===0?"true":void 0},r("strong",{},ee(o)),r("span",{class:"meta"},u===0?t:"Waiting"))))}function we(e,t){return r("header",{class:"unit-header"},r("h1",{},ee(e)),r("p",{class:"meta"},t))}function oe(){if(i.queue.length>0&&!i.queue.some(u=>u.isNew))return null;let e=["Find","Connect","Options"],o=["find","connect","options"].indexOf(i.screen);return r("ol",{class:"steps"},...e.map((u,g)=>{let v="ahead";return g<o?v="done":g===o&&(v="current"),r("li",{class:v,"aria-current":g===o?"step":void 0},u)}))}function qt(e){let t=e.probe?.status,o=e.name===""?"The device":e.name,u=e.probe?.message??"unknown";return t==="signInRequired"?r("div",{class:"field"},r("p",{class:"notice problem",role:"alert"},"The Tuya cloud no longer accepts the sign in of this plugin."),R("Sign in again",ne,"primary")):t==="unreachable"?r("p",{class:"notice problem",role:"alert"},`${o} did not answer. Check that it is plugged in and shows as online in the Smart Life app, then try again. ${u}`):t==="unsupported"?r("p",{class:"notice problem",role:"alert"},`The plugin cannot control ${o}: ${u}`):t==="failed"?r("p",{class:"notice problem",role:"alert"},`${o} answered with an error: ${u}`):null}function et(){let e=J();if(e===void 0)return[U()];let t=e.probe?.status==="unreachable"||e.probe?.status==="failed"||i.error!=="",o=e.isNew&&i.queue.length>1;return[oe(),ye(),we(e,`Connecting to the ${le(e.device,e.productName)}.`),U(),i.isBusy?null:qt(e),r("div",{class:"footer"},t?R("Try again",()=>{Ae(e)}):null,R(o?"Skip this one":"Cancel",o?Ye:K))]}function tt(){let e=i.saved,t=(i.setup?.devices??[]).some(o=>e.includes(o.name)&&o.needsRestart);return[r("header",{},r("h1",{},e.length===1?`${e[0]} is set up`:`${e.length} devices are set up`)),r("p",{class:"lead"},"They now appear in the Matter apps paired with Matterbridge. If Matterbridge is not paired yet, pair it from its home page."),t?r("p",{class:"help"},r("strong",{},Xe)):null,r("p",{class:"help"},Ee),r("div",{class:"footer"},R("Done",K,"primary"))]}function nt(e){return!e.isConfigured&&(e.support==="supported"||e.support==="unknownProduct")}function Qt(e){let t=[];return e.isConfigured&&t.push("Already set up."),e.support==="unknownProduct"&&t.push("The catalog does not list its product: the plugin checks its data points in the next step."),e.support==="otherKind"&&t.push("A kind of device the plugin does not control yet, such as a light: only switches, plugs and sensors for now."),e.support==="gateway"&&t.push("A gateway: the devices behind it are listed on their own."),e.support==="gateway"||e.support==="otherKind"||(e.online||t.push("The Tuya cloud says it is offline."),e.gatewayId!==void 0&&t.push("Behind a gateway."),e.lan!==void 0&&t.push(`Heard on your network at ${e.lan.host}.`),e.hasLocalKey||t.push("No local key from the cloud: reached through the cloud only.")),t}function Kt(e){let t=nt(e),o=`device-${e.deviceId}`,u=r("input",{type:"checkbox",id:o,checked:t&&i.selected.has(e.deviceId),disabled:!t,onchange:()=>{u.checked?i.selected.add(e.deviceId):i.selected.delete(e.deviceId),L()}});return r("li",{class:t?"found":"found unavailable"},r("label",{for:o},u,r("span",{},r("strong",{},e.name),r("span",{class:"meta"},` ${e.deviceId}, product ${e.productKey}${e.category===""?"":`, category ${e.category}`}`),...Qt(e).map(g=>r("span",{class:"meta note"},g)))))}function rt(){let e=i.devices.filter(o=>i.selected.has(o.deviceId)&&nt(o)),t=e.length===1?"Set up 1 device":`Set up ${e.length} devices`;return[oe(),r("header",{},r("h1",{},"Your Tuya devices")),U(),i.devices.length>0?r("ul",{class:"found-list"},...i.devices.map(Kt)):null,!i.isBusy&&i.devices.length===0&&i.error===""?r("p",{class:"empty"},"Your Tuya account has no device yet. Add your devices in the Smart Life app, then read the list again."):null,r("div",{class:"footer"},R("Read the list again",()=>{re()}),R("Cancel",K),R(t,()=>me(je(e)),"primary",e.length===0))]}function ot(e,t){if(t.unitFrom===void 0)return t.unit;let o=e[t.component]?.[t.unitFrom];return typeof o=="string"?o:t.unit}function be(e,t){return e[t.component]?.[t.control]}function Ut(e,t,o){if(e.kind==="temperature"){let g=ot(o,e);return`${String(t)} \xB0${g!==void 0&&/^f/i.test(g)?"F":"C"}`}if(e.kind==="humidity")return`${String(t)} % humidity`;if(e.kind==="illuminance")return`${String(t)} lx`;let u=t===!0||t===1||t==="true";return e.kind==="occupancy"?u?"Motion":"No motion":e.kind==="contact"?u?"Open":"Closed":u?"Water leak":"No leak"}function xe(e,t){if(e===void 0||t===void 0)return"";let o=[],u=e.outlets.length===1;for(let v of e.outlets){let k=be(t,v);typeof k=="boolean"&&o.push(u?k?"On":"Off":`${v.label} ${k?"on":"off"}`)}for(let v of e.sensors){let k=be(t,v);k!==void 0&&o.push(Ut(v,k,t))}let{meter:g}=e;for(let v of[g?.power,g?.voltage,g?.current,g?.energy]){if(v===void 0)continue;let k=be(t,v);typeof k=="number"&&o.push(`${k} ${v.unit}`)}if(e.battery!==void 0){let v=be(t,e.battery);typeof v=="number"&&o.push(`battery ${v} %`)}return o.join(", ")}function Se(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Vt(e){let{features:t}=e;if(t===void 0)return"as it was set up";let o=ue(t),u=F=>F!==o&&!e.hiddenFeatures.includes(F),g=t.outlets.filter(F=>u(F.id)).map(F=>F.label),v=t.sensors.filter(F=>u(F.id)).map(F=>F.label.toLowerCase()),k=t.settingSwitches.filter(F=>e.addedFeatures.includes(F.id)).map(F=>F.label.toLowerCase()),P=[t.outlets.length>0?"an outlet":`a ${t.sensors[0]?.label.toLowerCase()??""} sensor`];g.length>0&&P.push(Se(g)),t.meter!==void 0&&t.outlets.length>0&&!e.hiddenFeatures.includes(ae)&&P.push("the meter"),v.length>0&&P.push(`a sensor for the ${Se(v)}`),k.length>0&&P.push(`a switch for the ${Se(k)}`),t.battery!==void 0&&P.push("its battery");let ie=P.length>1||g.length>1;return`${Se(P)}${ie?e.isComposed?", all as one device":", each a device of its own":""}`}var Jt={lan:" on your network",cloud:" through the Tuya cloud"};function Wt(e){return e.status!=="online"||e.route!=="cloud"||e.isCloudOnly===!0?null:e.hasLan?r("p",{class:"meta"},"It did not answer on your network, so the plugin reaches it through the Tuya cloud."):r("p",{class:"meta"},"It was not heard on your network, so the plugin reaches it through the Tuya cloud. Where the plugin cannot hear it, such as on another subnet, enter its IP address in its options.")}function Gt(e){let o={online:`Online${e.route===void 0?"":Jt[e.route]}`,connecting:"Connecting\u2026",offline:"Not answering",stopped:"Not started"}[e.status],u=i.confirmingRemoval===e.deviceId,g=e.productName??`product ${e.productKey}`,v=e.status==="online"?xe(e.features,e.values):"";return r("li",{class:"device"},r("div",{class:"device-main"},r("h3",{},e.name),r("p",{class:"meta"},r("span",{class:`status ${e.status}`},o),` ${g}, ${e.deviceId}. In Matter: ${Vt(e)}.`),v===""?null:r("p",{class:"meta readings"},`${v}.`),Wt(e),e.status!=="online"&&e.error?r("p",{class:"meta problem-text"},e.error):null,e.needsRestart?r("p",{class:"meta"},r("strong",{},"Restart Matterbridge")," to apply the new options in Matter. Until then it keeps its current endpoints."):null),u?r("div",{class:"actions"},r("span",{class:"meta"},"Remove it from Matter too?"),R("Remove",()=>{ze(e)},"danger"),R("Keep",()=>{i.confirmingRemoval="",L()})):r("div",{class:"actions"},e.features===void 0?R("Set up again",()=>me([pe(e)]),"quiet",i.setup?.account===void 0):R("Options",()=>We(e),"quiet"),e.features!==void 0&&(e.status==="offline"||e.status==="stopped")?R("Reconnect",()=>{Ge(e)},"quiet"):null,R("Remove",()=>{i.confirmingRemoval=e.deviceId,L()})))}function Yt(){let e=i.setup?.account;if(i.setup===void 0)return null;if(e===void 0)return r("section",{class:"account"},r("p",{class:"notice problem",role:"alert"},"No Tuya account is signed in. The devices below stay in Matter and are reached on your network alone, and new devices cannot be added, until you sign in."),R("Sign in",ne,"primary"));let t=e.type==="smartLife"?`Signed in with the Smart Life app (User Code ${e.userCode}).`:`Signed in to the Tuya developer platform (project ${e.accessId}, data center ${se[e.dataCenter]}).`,o=i.confirmingSignOut?[r("span",{class:"meta"},"The devices stay in Matter, and keep working on your network."),R("Sign out",()=>{Je()},"danger"),R("Stay signed in",()=>{i.confirmingSignOut=!1,L()})]:[R(e.needsSignIn?"Sign in again":"Switch account",ne,e.needsSignIn?"primary":"quiet"),R("Sign out",()=>{i.confirmingSignOut=!0,L()})];return r("section",{class:"account"},r("p",{class:"meta"},t),e.needsSignIn?r("p",{class:"notice problem",role:"alert"},"The Tuya cloud no longer accepts this sign in. Sign in again to keep the devices reachable through the cloud and to add more."):null,r("div",{class:"actions"},...o))}function Zt(){let e=i.setup?.discoveryError;return e===void 0?null:r("p",{class:"notice problem",role:"alert"},`The plugin does not listen for devices on your network, so it reaches them through the Tuya cloud, or at the host given in their options: ${e}`)}function it(){let e=i.setup?.devices??[],t=i.setup?.account!==void 0&&!i.setup.account.needsSignIn;return[r("header",{},r("h1",{},"Tuya devices"),t?R("Add devices",()=>{re()},"primary"):null),U(),Yt(),Zt(),e.length===0&&i.setup?r("p",{class:"empty"},"No device is set up yet. Add one to control it from Matter."):r("ul",{class:"devices"},...e.map(Gt)),i.setup?null:R("Try again",()=>{ge()},"primary")]}var Xt={temperature:"temperature sensor",humidity:"humidity sensor",illuminance:"light sensor",occupancy:"motion sensor",contact:"contact sensor",waterLeak:"water leak detector"};function ce(e,t,o,u,g){let v=r("input",{type:"checkbox",id:e,checked:t,onchange:()=>g(v.checked)});return r("label",{class:"choice",for:e},v,r("span",{},r("strong",{},o),r("span",{class:"meta"},u)))}function st(e,t,o,u,g,v){let k=`${e}-${t}`,_=r("input",{type:"radio",name:e,id:k,checked:t===o,onchange:()=>v(t)});return r("label",{class:"choice",for:k},_,r("span",{},r("strong",{},u),r("span",{class:"meta"},g)))}function Re(e,t){return e.isComposed?`It appears as a part of "${e.name}", tagged "${t}".`:`It appears as "${e.name} ${t}".`}function Ce(e,t,o){let u=e.filter(g=>g!==t);return o?[...u,t]:u}function zt(e){let t=r("input",{type:"text",id:"device-name",value:e.name,maxLength:32,autocomplete:"off",spellcheck:!1});t.addEventListener("input",g=>{e.name=t.value.trim(),g.isComposing||L()});let o=e.device.cloudName,u=o===void 0?"":`Its name in the Smart Life app is "${o}". `;return r("section",{},r("h2",{},r("label",{for:"device-name"},"Name in Matter")),r("p",{class:"help"},`${u}The name here is what your Matter apps show, up to 32 characters, and no two devices of this plugin share one. A new name in the Smart Life app does not change it.`),r("div",{class:"inline-form"},t))}function en(e,t){let o=ue(t),u=[...t.outlets,...t.sensors].find(k=>k.id===o),g=[];for(let k of t.outlets)k.id!==o&&g.push(ce(`feature-${k.id}`,!e.hiddenFeatures.includes(k.id),k.label,`An on/off outlet. ${Re(e,k.label)}`,_=>{e.hiddenFeatures=Ce(e.hiddenFeatures,k.id,!_),L()}));if(t.meter!==void 0&&t.outlets.length>0){let k=[t.meter.power&&"power",t.meter.voltage&&"voltage",t.meter.current&&"current",t.meter.energy&&"energy used"].filter(_=>typeof _=="string");g.push(ce("feature-meter",!e.hiddenFeatures.includes(ae),"Meter",`The ${k.join(", ")} of "${e.name}", which few Matter apps show yet: Home Assistant does.`,_=>{e.hiddenFeatures=Ce(e.hiddenFeatures,ae,!_),L()}))}for(let k of t.sensors)k.id!==o&&g.push(ce(`feature-${k.id}`,!e.hiddenFeatures.includes(k.id),k.label,`A ${Xt[k.kind]}. ${Re(e,k.label)}`,_=>{e.hiddenFeatures=Ce(e.hiddenFeatures,k.id,!_),L()}));for(let k of t.settingSwitches)g.push(ce(`feature-${k.id}`,e.addedFeatures.includes(k.id),k.label,`A switch for a setting of the device. ${Re(e,k.label)}`,_=>{e.addedFeatures=Ce(e.addedFeatures,k.id,_),L()}));let v=u===void 0?"":`${u.label} is the device itself in Matter, and always appears there. `;return r("section",{},r("h2",{},"What appears in Matter"),r("p",{class:"help"},g.length===0?`${v}The device has nothing else to show.`:`${v}Choose what else appears with it.`),g.length===0?null:r("div",{class:"choices"},...g))}function tn(e){return r("section",{},r("h2",{},"One device or several"),r("p",{class:"help"},"The other outlets, the sensors and the switches can be parts of the device in Matter, or devices of their own beside it."),r("div",{class:"choices"},ce("composed",e.isComposed,"Show it as one device",`Your Matter app has one device, "${e.name}", and its parts move between rooms with it. A part has no name of its own in Matter, so an app may show the outlets as numbered outlets, and an app that shows no parts shows the device alone. Turned off, each is a device of its own with its own name, which your app puts in a room by itself.`,t=>{e.isComposed=t,L()})))}function nn(e){let t=r("input",{type:"text",id:"device-host",value:e.host,placeholder:"Leave empty to find it on your network",maxLength:253,autocomplete:"off",spellcheck:!1});t.addEventListener("input",()=>{e.host=t.value.trim()});let o=r("select",{id:"device-version",onchange:()=>{e.version=o.value}},r("option",{value:"",selected:e.version===""},"Not set"),...Fe.map(u=>r("option",{value:u,selected:u===e.version},u)));return r("div",{class:"field"},r("label",{for:"device-host"},"IP address or host name (optional)"),r("p",{class:"help"},"Most devices need neither of these: leave both empty, and the plugin finds the device by the broadcasts it sends. Only where it does not hear the device on your network, such as on another subnet or in a Docker container without host networking, enter its IP address, ideally one your router keeps for it, and the protocol version it speaks, which the Smart Life app does not show: tinytuya or tuya-local tell it. For a device behind a gateway, enter those of the gateway."),r("div",{class:"inline-form"},t),r("label",{for:"device-version"},"Protocol version (only with an IP address or host name)"),o)}function rn(e){let t=v=>{e.isCloudOnly=v==="cloud",L()},o=e.isCloudOnly?"cloud":"lan",u=e.probe?.route,g="";return u==="lan"?g=" It answered on your network just now.":u==="cloud"&&(g=" It answered through the Tuya cloud just now: the plugin switches to your network once it hears the device there."),r("section",{},r("h2",{id:"connection-title"},"Connection"),r("p",{class:"help"},`How the plugin reaches the device.${g}`),r("div",{class:"choices",role:"radiogroup","aria-labelledby":"connection-title"},st("connection","lan",o,"On your network first, through the Tuya cloud otherwise","The plugin hears the device on your network by the broadcasts it sends, and follows it to a new IP address. It keeps working while the Tuya cloud or the internet is down.",t),st("connection","cloud",o,"Through the Tuya cloud only","For a device that is not on the network of Matterbridge.",t)),e.isCloudOnly?null:nn(e))}function at(){let e=J();if(e===void 0)return[U()];let t=e.features??{outlets:[],settingSwitches:[],sensors:[]},o=xe(e.features,e.values);return[oe(),ye(),we(e,`Options for the ${le(e.device,e.productName)}.`),o===""?null:r("p",{class:"meta readings"},`It reports: ${o}.`),zt(e),en(e,t),tn(e),rn(e),e.isNew?null:r("p",{class:"help"},"Changing what appears in Matter, or whether it is one device, takes effect at the next restart of Matterbridge, which this page and Matterbridge ask for. Until then the device keeps its current endpoints. The name and the connection change at once."),U(),r("div",{class:"footer"},R("Cancel",K),R(e.isNew?`Add ${e.name}`:"Save options",()=>{Ze(e)},"primary"))]}var ft=Rt(lt(),1);function pt(e){let t=(0,ft.default)(0,"M");return t.addData(e),t.make(),r("div",{class:"qr",role:"img","aria-label":"QR code to scan with the Smart Life app",html:t.createSvgTag({cellSize:4,margin:2,scalable:!0})})}function ht(e,t,o){let u=`method-${e}`,g=r("input",{type:"radio",name:"method",id:u,checked:i.signIn.method===e,onchange:()=>{i.signIn.method=e,i.error="",L()}});return r("label",{class:"choice",for:u},g,r("span",{},r("strong",{},t),r("span",{class:"meta"},o)))}function on(){return r("section",{},r("h2",{id:"method-title"},"How to sign in"),r("div",{class:"choices",role:"radiogroup","aria-labelledby":"method-title"},ht("smartLife","With the Smart Life app (recommended)","Scan a QR code with the Smart Life or Tuya Smart app your devices are in. Nothing to set up first."),ht("developer","With a cloud project of the Tuya developer platform","For a project you made on platform.tuya.com, with your app account linked to it. Its IoT Core trial has to be extended from time to time.")))}function sn(){let e=r("input",{type:"text",id:"user-code",value:i.signIn.userCode,maxLength:32,autocomplete:"off",spellcheck:!1}),t=()=>{let o=e.value.trim();o!==""&&Qe(o)};return e.addEventListener("keydown",o=>{o.key==="Enter"&&t()}),[r("div",{class:"field"},r("label",{for:"user-code"},"User Code"),r("p",{class:"help"},"In the Smart Life app, open Me, then the settings, then Account and Security: the User Code is listed there. It is case-sensitive."),r("div",{class:"inline-form"},e)),r("div",{class:"footer"},R("Cancel",K),R("Show the QR code",t,"primary"))]}function an(e){return[r("p",{class:"lead"},"In the Smart Life app, tap the scan icon at the top of the home tab, scan this code, and confirm the sign in in the app."),pt(e),r("p",{class:"notice working",role:"status"},r("span",{class:"spinner"}),"Waiting for the app to confirm\u2026"),r("p",{class:"help"},"The plugin signs in as Home Assistant does, so the app may name Home Assistant. The code stays valid for a few minutes."),r("div",{class:"footer"},R("Cancel",()=>{Ue()}))]}function un(){let{login:e}=i;if(e.status==="waiting"&&e.qrCode!==void 0)return an(e.qrCode);let t=e.status==="expired"?"The QR code was not scanned in time. Show a new one to try again.":e.status==="failed"?`The sign in did not work: ${e.message??"unknown"}`:"";return[t===""?null:r("p",{class:"notice problem",role:"alert"},t),...sn()]}function cn(){let e=r("input",{type:"text",id:"access-id",value:i.signIn.accessId,maxLength:128,autocomplete:"username",spellcheck:!1}),t=r("input",{type:"password",id:"access-secret",maxLength:128,autocomplete:"current-password"}),o=r("select",{id:"data-center"},...Object.keys(se).map(g=>r("option",{value:g,selected:g===i.signIn.dataCenter},`${se[g]} (${g})`))),u=()=>{e.value.trim()===""||t.value.trim()===""||Ve(e.value.trim(),t.value.trim(),o.value)};return t.addEventListener("keydown",g=>{g.key==="Enter"&&u()}),[r("p",{class:"help"},"The cloud project needs your Smart Life account linked to it, under Devices > Link App Account, and the IoT Core service. Its Access ID and Access Secret are on its overview page."),r("div",{class:"field"},r("label",{for:"access-id"},"Access ID"),e),r("div",{class:"field"},r("label",{for:"access-secret"},"Access Secret"),r("p",{class:"help"},"It is kept in the configuration of the plugin."),t),r("div",{class:"field"},r("label",{for:"data-center"},"Data center"),r("p",{class:"help"},"The data center of your app account, which the project lists under Devices."),o),r("div",{class:"footer"},R("Cancel",K),R("Sign in",u,"primary"))]}function gt(){let e=i.setup?.account!==void 0,t=i.login.status==="waiting";return[r("header",{},r("h1",{},e?"Sign in to Tuya again":"Sign in to Tuya")),r("p",{class:"lead"},"The plugin lists your devices and gets the key each one encrypts its traffic with from the Tuya cloud, then reaches them on your network first. Your password is never asked for."),U(),t?null:on(),...i.signIn.method==="smartLife"?un():cn()]}function vt(){try{if(window.parent===window)return;let e=getComputedStyle(window.parent.document.body);for(let t of["--primary-color","--div-bg-color","--div-text-color","--main-bg-color","--main-label-color","--div-border-color","--main-light-color"]){let o=e.getPropertyValue(t).trim();o!==""&&document.documentElement.style.setProperty(`--host${t.slice(1)}`,o)}document.documentElement.style.setProperty("--host-font",e.fontFamily)}catch{}}qe({loading:()=>[r("p",{class:"notice working",role:"status"},r("span",{class:"spinner"}),"Loading\u2026")],home:it,signIn:gt,find:rt,connect:et,options:at,done:tt});vt();L();ge();
|
|
1
|
+
var Lt=Object.create;var _e=Object.defineProperty;var Mt=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var Et=Object.getPrototypeOf,Rt=Object.prototype.hasOwnProperty;var Nt=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(o){throw t=0,o}};var $t=(e,t,o,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let m of At(t))!Rt.call(e,m)&&m!==o&&_e(e,m,{get:()=>t[m],enumerable:!(u=Mt(t,m))||u.enumerable});return e};var Bt=(e,t,o)=>(o=e!=null?Lt(Et(e)):{},$t(t||!e||!e.__esModule?_e(o,"default",{value:e,enumerable:!0}):o,e));var gt=Nt((pt,ht)=>{var ft=(function(){var e=function(C,T){var b=236,x=17,c=C,y=o[T],s=null,n=0,w=null,f=[],v={},E=function(d,l){n=c*4+17,s=(function(a){for(var p=new Array(a),g=0;g<a;g+=1){p[g]=new Array(a);for(var S=0;S<a;S+=1)p[g][S]=null}return p})(n),R(0,0),R(n-7,0),R(0,n-7),H(),O(),Y(d,l),c>=7&&J(d),w==null&&(w=It(c,y,f)),Z(w,l)},R=function(d,l){for(var a=-1;a<=7;a+=1)if(!(d+a<=-1||n<=d+a))for(var p=-1;p<=7;p+=1)l+p<=-1||n<=l+p||(0<=a&&a<=6&&(p==0||p==6)||0<=p&&p<=6&&(a==0||a==6)||2<=a&&a<=4&&2<=p&&p<=4?s[d+a][l+p]=!0:s[d+a][l+p]=!1)},B=function(){for(var d=0,l=0,a=0;a<8;a+=1){E(!0,a);var p=m.getLostPoint(v);(a==0||d>p)&&(d=p,l=a)}return l},O=function(){for(var d=8;d<n-8;d+=1)s[d][6]==null&&(s[d][6]=d%2==0);for(var l=8;l<n-8;l+=1)s[6][l]==null&&(s[6][l]=l%2==0)},H=function(){for(var d=m.getPatternPosition(c),l=0;l<d.length;l+=1)for(var a=0;a<d.length;a+=1){var p=d[l],g=d[a];if(s[p][g]==null)for(var S=-2;S<=2;S+=1)for(var I=-2;I<=2;I+=1)S==-2||S==2||I==-2||I==2||S==0&&I==0?s[p+S][g+I]=!0:s[p+S][g+I]=!1}},J=function(d){for(var l=m.getBCHTypeNumber(c),a=0;a<18;a+=1){var p=!d&&(l>>a&1)==1;s[Math.floor(a/3)][a%3+n-8-3]=p}for(var a=0;a<18;a+=1){var p=!d&&(l>>a&1)==1;s[a%3+n-8-3][Math.floor(a/3)]=p}},Y=function(d,l){for(var a=y<<3|l,p=m.getBCHTypeInfo(a),g=0;g<15;g+=1){var S=!d&&(p>>g&1)==1;g<6?s[g][8]=S:g<8?s[g+1][8]=S:s[n-15+g][8]=S}for(var g=0;g<15;g+=1){var S=!d&&(p>>g&1)==1;g<8?s[8][n-g-1]=S:g<9?s[8][15-g-1+1]=S:s[8][15-g-1]=S}s[n-8][8]=!d},Z=function(d,l){for(var a=-1,p=n-1,g=7,S=0,I=m.getMaskFunction(l),k=n-1;k>0;k-=2)for(k==6&&(k-=1);;){for(var F=0;F<2;F+=1)if(s[p][k-F]==null){var _=!1;S<d.length&&(_=(d[S]>>>g&1)==1);var M=I(p,k-F);M&&(_=!_),s[p][k-F]=_,g-=1,g==-1&&(S+=1,g=7)}if(p+=a,p<0||n<=p){p-=a,a=-a;break}}},ee=function(d,l){for(var a=0,p=0,g=0,S=new Array(l.length),I=new Array(l.length),k=0;k<l.length;k+=1){var F=l[k].dataCount,_=l[k].totalCount-F;p=Math.max(p,F),g=Math.max(g,_),S[k]=new Array(F);for(var M=0;M<S[k].length;M+=1)S[k][M]=255&d.getBuffer()[M+a];a+=F;var Q=m.getErrorCorrectPolynomial(_),K=A(S[k],Q.getLength()-1),Fe=K.mod(Q);I[k]=new Array(Q.getLength()-1);for(var M=0;M<I[k].length;M+=1){var Pe=M+Fe.getLength()-I[k].length;I[k][M]=Pe>=0?Fe.getAt(Pe):0}}for(var Oe=0,M=0;M<l.length;M+=1)Oe+=l[M].totalCount;for(var De=new Array(Oe),ge=0,M=0;M<p;M+=1)for(var k=0;k<l.length;k+=1)M<S[k].length&&(De[ge]=S[k][M],ge+=1);for(var M=0;M<g;M+=1)for(var k=0;k<l.length;k+=1)M<I[k].length&&(De[ge]=I[k][M],ge+=1);return De},It=function(d,l,a){for(var p=L.getRSBlocks(d,l),g=N(),S=0;S<a.length;S+=1){var I=a[S];g.put(I.getMode(),4),g.put(I.getLength(),m.getLengthInBits(I.getMode(),d)),I.write(g)}for(var k=0,S=0;S<p.length;S+=1)k+=p[S].dataCount;if(g.getLengthInBits()>k*8)throw"code length overflow. ("+g.getLengthInBits()+">"+k*8+")";for(g.getLengthInBits()+4<=k*8&&g.put(0,4);g.getLengthInBits()%8!=0;)g.putBit(!1);for(;!(g.getLengthInBits()>=k*8||(g.put(b,8),g.getLengthInBits()>=k*8));)g.put(x,8);return ee(g,p)};v.addData=function(d,l){l=l||"Byte";var a=null;switch(l){case"Numeric":a=j(d);break;case"Alphanumeric":a=G(d);break;case"Byte":a=P(d);break;case"Kanji":a=xt(d);break;default:throw"mode:"+l}f.push(a),w=null},v.isDark=function(d,l){if(d<0||n<=d||l<0||n<=l)throw d+","+l;return s[d][l]},v.getModuleCount=function(){return n},v.make=function(){if(c<1){for(var d=1;d<40;d++){for(var l=L.getRSBlocks(d,y),a=N(),p=0;p<f.length;p++){var g=f[p];a.put(g.getMode(),4),a.put(g.getLength(),m.getLengthInBits(g.getMode(),d)),g.write(a)}for(var S=0,p=0;p<l.length;p++)S+=l[p].dataCount;if(a.getLengthInBits()<=S*8)break}c=d}E(!1,B())},v.createTableTag=function(d,l){d=d||2,l=typeof l>"u"?d*4:l;var a="";a+='<table style="',a+=" border-width: 0px; border-style: none;",a+=" border-collapse: collapse;",a+=" padding: 0px; margin: "+l+"px;",a+='">',a+="<tbody>";for(var p=0;p<v.getModuleCount();p+=1){a+="<tr>";for(var g=0;g<v.getModuleCount();g+=1)a+='<td style="',a+=" border-width: 0px; border-style: none;",a+=" border-collapse: collapse;",a+=" padding: 0px; margin: 0px;",a+=" width: "+d+"px;",a+=" height: "+d+"px;",a+=" background-color: ",a+=v.isDark(p,g)?"#000000":"#ffffff",a+=";",a+='"/>';a+="</tr>"}return a+="</tbody>",a+="</table>",a},v.createSvgTag=function(d,l,a,p){var g={};typeof arguments[0]=="object"&&(g=arguments[0],d=g.cellSize,l=g.margin,a=g.alt,p=g.title),d=d||2,l=typeof l>"u"?d*4:l,a=typeof a=="string"?{text:a}:a||{},a.text=a.text||null,a.id=a.text?a.id||"qrcode-description":null,p=typeof p=="string"?{text:p}:p||{},p.text=p.text||null,p.id=p.text?p.id||"qrcode-title":null;var S=v.getModuleCount()*d+l*2,I,k,F,_,M="",Q;for(Q="l"+d+",0 0,"+d+" -"+d+",0 0,-"+d+"z ",M+='<svg version="1.1" xmlns="http://www.w3.org/2000/svg"',M+=g.scalable?"":' width="'+S+'px" height="'+S+'px"',M+=' viewBox="0 0 '+S+" "+S+'" ',M+=' preserveAspectRatio="xMinYMin meet"',M+=p.text||a.text?' role="img" aria-labelledby="'+te([p.id,a.id].join(" ").trim())+'"':"",M+=">",M+=p.text?'<title id="'+te(p.id)+'">'+te(p.text)+"</title>":"",M+=a.text?'<description id="'+te(a.id)+'">'+te(a.text)+"</description>":"",M+='<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>',M+='<path d="',F=0;F<v.getModuleCount();F+=1)for(_=F*d+l,I=0;I<v.getModuleCount();I+=1)v.isDark(F,I)&&(k=I*d+l,M+="M"+k+","+_+Q);return M+='" stroke="transparent" fill="black"/>',M+="</svg>",M},v.createDataURL=function(d,l){d=d||2,l=typeof l>"u"?d*4:l;var a=v.getModuleCount()*d+l*2,p=l,g=a-l;return kt(a,a,function(S,I){if(p<=S&&S<g&&p<=I&&I<g){var k=Math.floor((S-p)/d),F=Math.floor((I-p)/d);return v.isDark(F,k)?0:1}else return 1})},v.createImgTag=function(d,l,a){d=d||2,l=typeof l>"u"?d*4:l;var p=v.getModuleCount()*d+l*2,g="";return g+="<img",g+=' src="',g+=v.createDataURL(d,l),g+='"',g+=' width="',g+=p,g+='"',g+=' height="',g+=p,g+='"',a&&(g+=' alt="',g+=te(a),g+='"'),g+="/>",g};var te=function(d){for(var l="",a=0;a<d.length;a+=1){var p=d.charAt(a);switch(p){case"<":l+="<";break;case">":l+=">";break;case"&":l+="&";break;case'"':l+=""";break;default:l+=p;break}}return l},Dt=function(d){var l=1;d=typeof d>"u"?l*2:d;var a=v.getModuleCount()*l+d*2,p=d,g=a-d,S,I,k,F,_,M={"\u2588\u2588":"\u2588","\u2588 ":"\u2580"," \u2588":"\u2584"," ":" "},Q={"\u2588\u2588":"\u2580","\u2588 ":"\u2580"," \u2588":" "," ":" "},K="";for(S=0;S<a;S+=2){for(k=Math.floor((S-p)/l),F=Math.floor((S+1-p)/l),I=0;I<a;I+=1)_="\u2588",p<=I&&I<g&&p<=S&&S<g&&v.isDark(k,Math.floor((I-p)/l))&&(_=" "),p<=I&&I<g&&p<=S+1&&S+1<g&&v.isDark(F,Math.floor((I-p)/l))?_+=" ":_+="\u2588",K+=d<1&&S+1>=g?Q[_]:M[_];K+=`
|
|
2
|
+
`}return a%2&&d>0?K.substring(0,K.length-a-1)+Array(a+1).join("\u2580"):K.substring(0,K.length-1)};return v.createASCII=function(d,l){if(d=d||1,d<2)return Dt(l);d-=1,l=typeof l>"u"?d*2:l;var a=v.getModuleCount()*d+l*2,p=l,g=a-l,S,I,k,F,_=Array(d+1).join("\u2588\u2588"),M=Array(d+1).join(" "),Q="",K="";for(S=0;S<a;S+=1){for(k=Math.floor((S-p)/d),K="",I=0;I<a;I+=1)F=1,p<=I&&I<g&&p<=S&&S<g&&v.isDark(k,Math.floor((I-p)/d))&&(F=0),K+=F?_:M;for(k=0;k<d;k+=1)Q+=K+`
|
|
3
|
+
`}return Q.substring(0,Q.length-1)},v.renderTo2dContext=function(d,l){l=l||2;for(var a=v.getModuleCount(),p=0;p<a;p++)for(var g=0;g<a;g++)d.fillStyle=v.isDark(p,g)?"black":"white",d.fillRect(p*l,g*l,l,l)},v};e.stringToBytesFuncs={default:function(C){for(var T=[],b=0;b<C.length;b+=1){var x=C.charCodeAt(b);T.push(x&255)}return T}},e.stringToBytes=e.stringToBytesFuncs.default,e.createStringToBytes=function(C,T){var b=(function(){for(var c=Ct(C),y=function(){var O=c.read();if(O==-1)throw"eof";return O},s=0,n={};;){var w=c.read();if(w==-1)break;var f=y(),v=y(),E=y(),R=String.fromCharCode(w<<8|f),B=v<<8|E;n[R]=B,s+=1}if(s!=T)throw s+" != "+T;return n})(),x=63;return function(c){for(var y=[],s=0;s<c.length;s+=1){var n=c.charCodeAt(s);if(n<128)y.push(n);else{var w=b[c.charAt(s)];typeof w=="number"?(w&255)==w?y.push(w):(y.push(w>>>8),y.push(w&255)):y.push(x)}}return y}};var t={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},o={L:1,M:0,Q:3,H:2},u={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},m=(function(){var C=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],T=1335,b=7973,x=21522,c={},y=function(s){for(var n=0;s!=0;)n+=1,s>>>=1;return n};return c.getBCHTypeInfo=function(s){for(var n=s<<10;y(n)-y(T)>=0;)n^=T<<y(n)-y(T);return(s<<10|n)^x},c.getBCHTypeNumber=function(s){for(var n=s<<12;y(n)-y(b)>=0;)n^=b<<y(n)-y(b);return s<<12|n},c.getPatternPosition=function(s){return C[s-1]},c.getMaskFunction=function(s){switch(s){case u.PATTERN000:return function(n,w){return(n+w)%2==0};case u.PATTERN001:return function(n,w){return n%2==0};case u.PATTERN010:return function(n,w){return w%3==0};case u.PATTERN011:return function(n,w){return(n+w)%3==0};case u.PATTERN100:return function(n,w){return(Math.floor(n/2)+Math.floor(w/3))%2==0};case u.PATTERN101:return function(n,w){return n*w%2+n*w%3==0};case u.PATTERN110:return function(n,w){return(n*w%2+n*w%3)%2==0};case u.PATTERN111:return function(n,w){return(n*w%3+(n+w)%2)%2==0};default:throw"bad maskPattern:"+s}},c.getErrorCorrectPolynomial=function(s){for(var n=A([1],0),w=0;w<s;w+=1)n=n.multiply(A([1,h.gexp(w)],0));return n},c.getLengthInBits=function(s,n){if(1<=n&&n<10)switch(s){case t.MODE_NUMBER:return 10;case t.MODE_ALPHA_NUM:return 9;case t.MODE_8BIT_BYTE:return 8;case t.MODE_KANJI:return 8;default:throw"mode:"+s}else if(n<27)switch(s){case t.MODE_NUMBER:return 12;case t.MODE_ALPHA_NUM:return 11;case t.MODE_8BIT_BYTE:return 16;case t.MODE_KANJI:return 10;default:throw"mode:"+s}else if(n<41)switch(s){case t.MODE_NUMBER:return 14;case t.MODE_ALPHA_NUM:return 13;case t.MODE_8BIT_BYTE:return 16;case t.MODE_KANJI:return 12;default:throw"mode:"+s}else throw"type:"+n},c.getLostPoint=function(s){for(var n=s.getModuleCount(),w=0,f=0;f<n;f+=1)for(var v=0;v<n;v+=1){for(var E=0,R=s.isDark(f,v),B=-1;B<=1;B+=1)if(!(f+B<0||n<=f+B))for(var O=-1;O<=1;O+=1)v+O<0||n<=v+O||B==0&&O==0||R==s.isDark(f+B,v+O)&&(E+=1);E>5&&(w+=3+E-5)}for(var f=0;f<n-1;f+=1)for(var v=0;v<n-1;v+=1){var H=0;s.isDark(f,v)&&(H+=1),s.isDark(f+1,v)&&(H+=1),s.isDark(f,v+1)&&(H+=1),s.isDark(f+1,v+1)&&(H+=1),(H==0||H==4)&&(w+=3)}for(var f=0;f<n;f+=1)for(var v=0;v<n-6;v+=1)s.isDark(f,v)&&!s.isDark(f,v+1)&&s.isDark(f,v+2)&&s.isDark(f,v+3)&&s.isDark(f,v+4)&&!s.isDark(f,v+5)&&s.isDark(f,v+6)&&(w+=40);for(var v=0;v<n;v+=1)for(var f=0;f<n-6;f+=1)s.isDark(f,v)&&!s.isDark(f+1,v)&&s.isDark(f+2,v)&&s.isDark(f+3,v)&&s.isDark(f+4,v)&&!s.isDark(f+5,v)&&s.isDark(f+6,v)&&(w+=40);for(var J=0,v=0;v<n;v+=1)for(var f=0;f<n;f+=1)s.isDark(f,v)&&(J+=1);var Y=Math.abs(100*J/n/n-50)/5;return w+=Y*10,w},c})(),h=(function(){for(var C=new Array(256),T=new Array(256),b=0;b<8;b+=1)C[b]=1<<b;for(var b=8;b<256;b+=1)C[b]=C[b-4]^C[b-5]^C[b-6]^C[b-8];for(var b=0;b<255;b+=1)T[C[b]]=b;var x={};return x.glog=function(c){if(c<1)throw"glog("+c+")";return T[c]},x.gexp=function(c){for(;c<0;)c+=255;for(;c>=256;)c-=255;return C[c]},x})();function A(C,T){if(typeof C.length>"u")throw C.length+"/"+T;var b=(function(){for(var c=0;c<C.length&&C[c]==0;)c+=1;for(var y=new Array(C.length-c+T),s=0;s<C.length-c;s+=1)y[s]=C[s+c];return y})(),x={};return x.getAt=function(c){return b[c]},x.getLength=function(){return b.length},x.multiply=function(c){for(var y=new Array(x.getLength()+c.getLength()-1),s=0;s<x.getLength();s+=1)for(var n=0;n<c.getLength();n+=1)y[s+n]^=h.gexp(h.glog(x.getAt(s))+h.glog(c.getAt(n)));return A(y,0)},x.mod=function(c){if(x.getLength()-c.getLength()<0)return x;for(var y=h.glog(x.getAt(0))-h.glog(c.getAt(0)),s=new Array(x.getLength()),n=0;n<x.getLength();n+=1)s[n]=x.getAt(n);for(var n=0;n<c.getLength();n+=1)s[n]^=h.gexp(h.glog(c.getAt(n))+y);return A(s,0).mod(c)},x}var L=(function(){var C=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],T=function(c,y){var s={};return s.totalCount=c,s.dataCount=y,s},b={},x=function(c,y){switch(y){case o.L:return C[(c-1)*4+0];case o.M:return C[(c-1)*4+1];case o.Q:return C[(c-1)*4+2];case o.H:return C[(c-1)*4+3];default:return}};return b.getRSBlocks=function(c,y){var s=x(c,y);if(typeof s>"u")throw"bad rs block @ typeNumber:"+c+"/errorCorrectionLevel:"+y;for(var n=s.length/3,w=[],f=0;f<n;f+=1)for(var v=s[f*3+0],E=s[f*3+1],R=s[f*3+2],B=0;B<v;B+=1)w.push(T(E,R));return w},b})(),N=function(){var C=[],T=0,b={};return b.getBuffer=function(){return C},b.getAt=function(x){var c=Math.floor(x/8);return(C[c]>>>7-x%8&1)==1},b.put=function(x,c){for(var y=0;y<c;y+=1)b.putBit((x>>>c-y-1&1)==1)},b.getLengthInBits=function(){return T},b.putBit=function(x){var c=Math.floor(T/8);C.length<=c&&C.push(0),x&&(C[c]|=128>>>T%8),T+=1},b},j=function(C){var T=t.MODE_NUMBER,b=C,x={};x.getMode=function(){return T},x.getLength=function(s){return b.length},x.write=function(s){for(var n=b,w=0;w+2<n.length;)s.put(c(n.substring(w,w+3)),10),w+=3;w<n.length&&(n.length-w==1?s.put(c(n.substring(w,w+1)),4):n.length-w==2&&s.put(c(n.substring(w,w+2)),7))};var c=function(s){for(var n=0,w=0;w<s.length;w+=1)n=n*10+y(s.charAt(w));return n},y=function(s){if("0"<=s&&s<="9")return s.charCodeAt(0)-48;throw"illegal char :"+s};return x},G=function(C){var T=t.MODE_ALPHA_NUM,b=C,x={};x.getMode=function(){return T},x.getLength=function(y){return b.length},x.write=function(y){for(var s=b,n=0;n+1<s.length;)y.put(c(s.charAt(n))*45+c(s.charAt(n+1)),11),n+=2;n<s.length&&y.put(c(s.charAt(n)),6)};var c=function(y){if("0"<=y&&y<="9")return y.charCodeAt(0)-48;if("A"<=y&&y<="Z")return y.charCodeAt(0)-65+10;switch(y){case" ":return 36;case"$":return 37;case"%":return 38;case"*":return 39;case"+":return 40;case"-":return 41;case".":return 42;case"/":return 43;case":":return 44;default:throw"illegal char :"+y}};return x},P=function(C){var T=t.MODE_8BIT_BYTE,b=C,x=e.stringToBytes(C),c={};return c.getMode=function(){return T},c.getLength=function(y){return x.length},c.write=function(y){for(var s=0;s<x.length;s+=1)y.put(x[s],8)},c},xt=function(C){var T=t.MODE_KANJI,b=C,x=e.stringToBytesFuncs.SJIS;if(!x)throw"sjis not supported.";(function(s,n){var w=x(s);if(w.length!=2||(w[0]<<8|w[1])!=n)throw"sjis not supported."})("\u53CB",38726);var c=x(C),y={};return y.getMode=function(){return T},y.getLength=function(s){return~~(c.length/2)},y.write=function(s){for(var n=c,w=0;w+1<n.length;){var f=(255&n[w])<<8|255&n[w+1];if(33088<=f&&f<=40956)f-=33088;else if(57408<=f&&f<=60351)f-=49472;else throw"illegal char at "+(w+1)+"/"+f;f=(f>>>8&255)*192+(f&255),s.put(f,13),w+=2}if(w<n.length)throw"illegal char at "+(w+1)},y},Be=function(){var C=[],T={};return T.writeByte=function(b){C.push(b&255)},T.writeShort=function(b){T.writeByte(b),T.writeByte(b>>>8)},T.writeBytes=function(b,x,c){x=x||0,c=c||b.length;for(var y=0;y<c;y+=1)T.writeByte(b[y+x])},T.writeString=function(b){for(var x=0;x<b.length;x+=1)T.writeByte(b.charCodeAt(x))},T.toByteArray=function(){return C},T.toString=function(){var b="";b+="[";for(var x=0;x<C.length;x+=1)x>0&&(b+=","),b+=C[x];return b+="]",b},T},St=function(){var C=0,T=0,b=0,x="",c={},y=function(n){x+=String.fromCharCode(s(n&63))},s=function(n){if(!(n<0)){if(n<26)return 65+n;if(n<52)return 97+(n-26);if(n<62)return 48+(n-52);if(n==62)return 43;if(n==63)return 47}throw"n:"+n};return c.writeByte=function(n){for(C=C<<8|n&255,T+=8,b+=1;T>=6;)y(C>>>T-6),T-=6},c.flush=function(){if(T>0&&(y(C<<6-T),C=0,T=0),b%3!=0)for(var n=3-b%3,w=0;w<n;w+=1)x+="="},c.toString=function(){return x},c},Ct=function(C){var T=C,b=0,x=0,c=0,y={};y.read=function(){for(;c<8;){if(b>=T.length){if(c==0)return-1;throw"unexpected end of file./"+c}var n=T.charAt(b);if(b+=1,n=="=")return c=0,-1;if(n.match(/^\s$/))continue;x=x<<6|s(n.charCodeAt(0)),c+=6}var w=x>>>c-8&255;return c-=8,w};var s=function(n){if(65<=n&&n<=90)return n-65;if(97<=n&&n<=122)return n-97+26;if(48<=n&&n<=57)return n-48+52;if(n==43)return 62;if(n==47)return 63;throw"c:"+n};return y},Tt=function(C,T){var b=C,x=T,c=new Array(C*T),y={};y.setPixel=function(f,v,E){c[v*b+f]=E},y.write=function(f){f.writeString("GIF87a"),f.writeShort(b),f.writeShort(x),f.writeByte(128),f.writeByte(0),f.writeByte(0),f.writeByte(0),f.writeByte(0),f.writeByte(0),f.writeByte(255),f.writeByte(255),f.writeByte(255),f.writeString(","),f.writeShort(0),f.writeShort(0),f.writeShort(b),f.writeShort(x),f.writeByte(0);var v=2,E=n(v);f.writeByte(v);for(var R=0;E.length-R>255;)f.writeByte(255),f.writeBytes(E,R,255),R+=255;f.writeByte(E.length-R),f.writeBytes(E,R,E.length-R),f.writeByte(0),f.writeString(";")};var s=function(f){var v=f,E=0,R=0,B={};return B.write=function(O,H){if(O>>>H)throw"length over";for(;E+H>=8;)v.writeByte(255&(O<<E|R)),H-=8-E,O>>>=8-E,R=0,E=0;R=O<<E|R,E=E+H},B.flush=function(){E>0&&v.writeByte(R)},B},n=function(f){for(var v=1<<f,E=(1<<f)+1,R=f+1,B=w(),O=0;O<v;O+=1)B.add(String.fromCharCode(O));B.add(String.fromCharCode(v)),B.add(String.fromCharCode(E));var H=Be(),J=s(H);J.write(v,R);var Y=0,Z=String.fromCharCode(c[Y]);for(Y+=1;Y<c.length;){var ee=String.fromCharCode(c[Y]);Y+=1,B.contains(Z+ee)?Z=Z+ee:(J.write(B.indexOf(Z),R),B.size()<4095&&(B.size()==1<<R&&(R+=1),B.add(Z+ee)),Z=ee)}return J.write(B.indexOf(Z),R),J.write(E,R),J.flush(),H.toByteArray()},w=function(){var f={},v=0,E={};return E.add=function(R){if(E.contains(R))throw"dup key:"+R;f[R]=v,v+=1},E.size=function(){return v},E.indexOf=function(R){return f[R]},E.contains=function(R){return typeof f[R]<"u"},E};return y},kt=function(C,T,b){for(var x=Tt(C,T),c=0;c<T;c+=1)for(var y=0;y<C;y+=1)x.setPixel(y,c,b(y,c));var s=Be();x.write(s);for(var n=St(),w=s.toByteArray(),f=0;f<w.length;f+=1)n.writeByte(w[f]);return n.flush(),"data:image/gif;base64,"+n};return e})();(function(){ft.stringToBytesFuncs["UTF-8"]=function(e){function t(o){for(var u=[],m=0;m<o.length;m++){var h=o.charCodeAt(m);h<128?u.push(h):h<2048?u.push(192|h>>6,128|h&63):h<55296||h>=57344?u.push(224|h>>12,128|h>>6&63,128|h&63):(m++,h=65536+((h&1023)<<10|o.charCodeAt(m)&1023),u.push(240|h>>18,128|h>>12&63,128|h>>6&63,128|h&63))}return u}return t(e)}})();(function(e){typeof define=="function"&&define.amd?define([],e):typeof pt=="object"&&(ht.exports=e())})(function(){return ft})});var de={cn:"China",us:"Western America","us-e":"Eastern America",eu:"Central Europe","eu-w":"Western Europe",in:"India",sg:"Singapore"},He=["3.1","3.2","3.3","3.4","3.5"],le="meter";async function q(e,t){try{let[o,u]=e.split(" "),m={method:o};t!==void 0&&(m.headers={"Content-Type":"application/json"},m.body=JSON.stringify(t));let h=await fetch(new URL(`api/${u}`,document.baseURI),m);if(h.status===503)return{ok:!1,error:"The plugin is not running. Start it in Matterbridge, then reload this page."};let A=await h.json();return"ok"in A?A:{ok:!1,error:A.error??`The plugin answered with status ${h.status}`}}catch{return{ok:!1,error:"Matterbridge did not answer. Check that it is running, then try again."}}}var i={screen:"loading",setup:void 0,signIn:{method:"smartLife",userCode:"",accessId:"",dataCenter:"eu"},login:{status:"idle"},devices:[],selected:new Set,queue:[],saved:[],handled:[],isBusy:!1,busyText:"",error:"",info:"",confirmingRemoval:"",confirmingSignOut:!1};function W(){return i.queue[0]}function ne(e){return e.name===""?e.device.deviceId:e.name}function me(e,t){let o=t===void 0?"device":t;return e.cloudName===void 0?`${o} ${e.deviceId}`:`${o} ${e.deviceId}, named "${e.cloudName}" in the Smart Life app`}var je=32;function Le(e,t){if(!qe(e)||!qe(t))return JSON.stringify(e)===JSON.stringify(t);let o=Object.keys(e);return o.length===Object.keys(t).length&&o.every(u=>Le(e[u],t[u]))}function qe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ve(e){return{hiddenFeatures:[...e.hiddenFeatures],addedFeatures:[...e.addedFeatures],isComposed:e.isComposed}}function re(e){return(e.lights[0]??e.outlets[0]??e.sensors[0])?.id}function fe(e){let[t]=e.outlets;return e.meter!==void 0&&t!==void 0&&re(e)===t.id}function Me(e,t){let o=re(t),u=new Set([...t.lights,...t.outlets,...t.sensors].map(h=>h.id).filter(h=>h!==o));fe(t)&&u.add("meter");let m=new Set(t.settingSwitches.map(h=>h.id));return{hiddenFeatures:e.hiddenFeatures.filter(h=>u.has(h)),addedFeatures:e.addedFeatures.filter(h=>m.has(h)),isComposed:e.isComposed}}function Ft(e,t){let o=e.trim().slice(0,je).trimEnd();if(o===""||!t.has(o))return o;for(let u=2;;u++){let m=` ${u}`,h=`${o.slice(0,je-m.length).trimEnd()}${m}`;if(!t.has(h))return h}}function Qe(e){let t=new Set((i.setup?.devices??[]).map(o=>o.name));return e.map(o=>{let u=Ft(o.name,t);return t.add(u),{device:{deviceId:o.deviceId,cloudName:o.name,productKey:o.productKey,category:o.category},name:u,host:"",version:"",isCloudOnly:!1,isNew:!0,hiddenFeatures:[],addedFeatures:[],isComposed:!1}})}function ye(e){return{device:{deviceId:e.deviceId,cloudName:e.cloudName,productKey:e.productKey,category:e.category},name:e.name,host:e.host??"",version:e.version??"",isCloudOnly:e.isCloudOnly??!1,isNew:!1,catalogFile:e.catalogFile,model:e.model,productName:e.productName,features:e.features,values:e.values,...ve(e)}}var Ae;function Ke(e){Ae=e}function D(){let e=document.getElementById("app");if(e===null||Ae===void 0)return;let t=`${i.screen}:${W()?.device.deviceId??""}`,o=e.dataset.form===t,u=document.activeElement,m=u instanceof HTMLElement?u.id:"",h=u instanceof HTMLInputElement&&(u.type==="text"||u.type==="password")?{start:u.selectionStart,end:u.selectionEnd}:void 0,A=new Map;for(let N of e.querySelectorAll("input[type=text], input[type=email], input[type=password]"))N.id!==""&&A.set(N.id,N.value);if(e.replaceChildren(...Ae[i.screen]().filter(N=>N!==!1&&N!==null&&N!==void 0)),e.dataset.form=t,!o)return;for(let[N,j]of A){let G=document.getElementById(N);G instanceof HTMLInputElement&&(G.value=j)}if(m==="")return;let L=document.getElementById(m);L?.focus(),h!==void 0&&L instanceof HTMLInputElement&&L.setSelectionRange(h.start,h.end)}async function X(e,t){i.isBusy=!0,i.busyText=e,i.error="",i.info="",D();try{return await t()}finally{i.isBusy=!1,D()}}async function be(){let e=await q("GET state");if(!e.ok){i.error=e.error,i.screen="home",D();return}if(z(e.state),e.state.account===void 0&&e.state.devices.length===0){ie();return}if(e.state.account!==void 0&&e.state.devices.length===0&&!e.state.account.needsSignIn){await se();return}i.screen="home",D(),Pt()}async function Pt(){if(i.setup?.account===void 0)return;let e=await q("POST sync");!e.ok||JSON.stringify(e.state)===JSON.stringify(i.setup)||(z(e.state),D())}var Ot=2e3,Ee;function z(e){i.setup=e,!(Ee!==void 0||!e.devices.some(t=>t.status==="connecting"))&&(Ee=window.setTimeout(()=>{Ee=void 0,_t()},Ot))}async function _t(){let e=await q("GET state");if(!e.ok)return;let t=JSON.stringify(e.state)!==JSON.stringify(i.setup);z(e.state),t&&i.screen==="home"&&D()}async function oe(){let e=await q("GET state");e.ok&&z(e.state)}function U(){xe(),i.queue=[],i.saved=[],i.handled=[],i.error="",i.info="",i.screen="home",oe().then(D),D()}function ie(){let e=i.setup?.account;e?.type==="smartLife"&&(i.signIn={...i.signIn,method:"smartLife",userCode:e.userCode}),e?.type==="developer"&&(i.signIn={...i.signIn,method:"developer",accessId:e.accessId,dataCenter:e.dataCenter}),i.login={status:"idle"},i.error="",i.info="",i.screen="signIn",D()}var Ht=2e3,we;function xe(){window.clearInterval(we),we=void 0}async function Ue(e){i.signIn.userCode=e,xe();let t=await X("Asking the Smart Life cloud for a QR code\u2026",async()=>q("POST qr-code",{userCode:e}));if(!t.ok){i.error=t.error,D();return}i.login=t.login,D(),we=window.setInterval(()=>{jt()},Ht)}async function jt(){let e=await q("GET qr-login");if(!e.ok||i.screen!=="signIn"||we===void 0)return;let{login:t}=e;t.status!=="waiting"&&(xe(),await qt(t,e.state))}async function qt(e,t){if(i.login=e,e.status!=="signedIn"){D();return}z(t),await Ve(t)}async function Ve(e){i.login={status:"idle"},e.devices.length===0?await se():U()}async function Je(){xe(),i.login={status:"idle"},await q("POST cancel-qr-code"),D()}async function We(e,t,o){i.signIn={...i.signIn,accessId:e,dataCenter:o};let u=await X("Signing in to the Tuya developer platform\u2026",async()=>q("POST developer-login",{accessId:e,accessSecret:t,dataCenter:o}));if(!u.ok){i.error=u.error,D();return}z(u.state),await Ve(u.state)}async function Ge(){let e=await X("Signing out\u2026",async()=>q("POST sign-out"));i.confirmingSignOut=!1,e.ok||(i.error=e.error),await oe(),D()}async function se(){i.screen="find";let e=await X("Reading the devices of your Tuya account\u2026",async()=>q("POST devices"));if(!e.ok){i.error=`The devices could not be read: ${e.error}`,D();return}await oe(),i.devices=e.devices;for(let t of e.devices)!t.isConfigured&&t.support==="supported"&&i.selected.add(t.deviceId);D()}function Se(e){i.queue=e,i.saved=[],i.handled=[],Re()}function Ye(e){i.queue=[ye(e)],i.saved=[],i.handled=[],i.error="",i.info="",i.screen="options",D()}async function Ze(e){let t=await X(`Reconnecting ${e.name}\u2026`,async()=>q("POST reconnect",{deviceId:e.deviceId}));t.ok?z(t.state):i.error=t.error,D()}async function Re(){let e=W();if(e===void 0){i.screen=i.saved.length>0?"done":"home",await oe(),D();return}i.screen="connect",i.error="",i.info="",e.probe=void 0,D(),await Ne(e)}async function Ne(e){let t=await X(`Connecting to ${ne(e)} on your network, and through the Tuya cloud\u2026`,async()=>q("POST probe",{deviceId:e.device.deviceId}));if(!t.ok){i.error=t.error,D();return}let{result:o}=t;e.probe=o,o.status==="signInRequired"&&await oe(),o.status==="ready"&&o.features!==void 0&&(o.catalogFile!==void 0||o.model!==void 0)&&(e.features=o.features,e.values=o.values,e.productName=o.productName,(e.catalogFile!==void 0||e.model!==void 0)&&(e.catalogFile!==o.catalogFile||!Le(e.model,o.model))&&Object.assign(e,{hiddenFeatures:[],addedFeatures:[]}),e.catalogFile=o.catalogFile,e.model=o.model,Object.assign(e,Me(ve(e),o.features)),i.screen="options"),D()}function Xe(){let e=i.queue.shift();e!==void 0&&i.handled.push({label:ne(e),isSaved:!1}),Re()}async function ze(e){let t=e.name.trim(),o=Qt(e,t)||Kt(e);if(o!==""){i.error=o,D();return}if(e.catalogFile===void 0&&e.model===void 0)return;let{device:u}=e,m=!e.isCloudOnly&&e.host!=="",h={deviceId:u.deviceId,name:t,productKey:u.productKey,catalogFile:e.catalogFile,model:e.model,category:u.category,...Me(ve(e),e.features??{lights:[],outlets:[],settingSwitches:[],sensors:[]}),host:m?e.host:void 0,version:m?e.version:void 0,isCloudOnly:e.isCloudOnly||void 0},A=await X(`Saving ${t}\u2026`,async()=>q("POST device",{device:h}));if(!A.ok){i.error=A.error,D();return}z(A.state),i.saved.push(t),i.handled.push({label:t,isSaved:!0}),i.queue.shift(),await Re()}function Qt(e,t){return t===""?"Give the device a name: it is the name it gets in Matter.":(i.setup?.devices??[]).some(u=>u.name===t&&u.deviceId!==e.device.deviceId)?`"${t}" is already the name of another device. Pick a different one.`:""}function Kt(e){return e.isCloudOnly||e.host===""?"":/^[A-Za-z0-9](?:[A-Za-z0-9.-]{0,251}[A-Za-z0-9])?$/.test(e.host)?e.version===""?"Pick the protocol version the device speaks at that host, or leave the host empty.":"":`"${e.host}" is not a host name or an IPv4 address.`}var $e="Matterbridge's own list of devices shows the change once you reload its page.",et="Restart Matterbridge to apply the new options in Matter: until then the device keeps its current endpoints.";async function tt(e){let t=await X(`Removing ${e.name}\u2026`,async()=>q("POST remove-device",{deviceId:e.deviceId}));i.confirmingRemoval="",t.ok?i.info=`${e.name} is removed. ${$e}`:i.error=t.error,await oe(),D()}function r(e,t={},...o){let u=document.createElement(e);for(let[m,h]of Object.entries(t))h===void 0||h===!1||(m==="class"?u.className=String(h):m==="html"?u.innerHTML=String(h):m.startsWith("on")&&typeof h=="function"?u.addEventListener(m.slice(2),h):m in u?u[m]=h:u.setAttribute(m,String(h)));for(let m of o)m!==!1&&m!==null&&m!==void 0&&u.append(m);return u}function $(e,t,o="quiet",u=!1){return r("button",{type:"button",class:`button ${o}`,onclick:t,disabled:u||i.isBusy},e)}function V(){return i.isBusy?r("p",{class:"notice working",role:"status"},r("span",{class:"spinner"}),i.busyText):i.error!==""?r("p",{class:"notice problem",role:"alert"},i.error):i.info!==""?r("p",{class:"notice",role:"status"},i.info):null}function Ce(){let e=W();if(e===void 0||!e.isNew||i.handled.length+i.queue.length<2)return null;let t=i.screen==="connect"?"Connecting":"Choosing options";return r("ol",{class:"units","aria-label":"Devices in this setup"},...i.handled.map(o=>r("li",{class:o.isSaved?"done":"skipped"},r("strong",{},o.label),r("span",{class:"meta"},o.isSaved?"Added":"Skipped"))),...i.queue.map((o,u)=>r("li",{class:u===0?"current":"ahead","aria-current":u===0?"true":void 0},r("strong",{},ne(o)),r("span",{class:"meta"},u===0?t:"Waiting"))))}function Te(e,t){return r("header",{class:"unit-header"},r("h1",{},ne(e)),r("p",{class:"meta"},t))}function ae(){if(i.queue.length>0&&!i.queue.some(u=>u.isNew))return null;let e=["Find","Connect","Options"],o=["find","connect","options"].indexOf(i.screen);return r("ol",{class:"steps"},...e.map((u,m)=>{let h="ahead";return m<o?h="done":m===o&&(h="current"),r("li",{class:h,"aria-current":m===o?"step":void 0},u)}))}function Ut(e){let t=e.probe?.status,o=e.name===""?"The device":e.name,u=e.probe?.message??"unknown";return t==="signInRequired"?r("div",{class:"field"},r("p",{class:"notice problem",role:"alert"},"The Tuya cloud no longer accepts the sign in of this plugin."),$("Sign in again",ie,"primary")):t==="unreachable"?r("p",{class:"notice problem",role:"alert"},`${o} did not answer. Check that it is plugged in and shows as online in the Smart Life app, then try again. ${u}`):t==="unsupported"?r("p",{class:"notice problem",role:"alert"},`The plugin cannot control ${o}: ${u}`):t==="failed"?r("p",{class:"notice problem",role:"alert"},`${o} answered with an error: ${u}`):null}function nt(){let e=W();if(e===void 0)return[V()];let t=e.probe?.status==="unreachable"||e.probe?.status==="failed"||i.error!=="",o=e.isNew&&i.queue.length>1;return[ae(),Ce(),Te(e,`Connecting to the ${me(e.device,e.productName)}.`),V(),i.isBusy?null:Ut(e),r("div",{class:"footer"},t?$("Try again",()=>{Ne(e)}):null,$(o?"Skip this one":"Cancel",o?Xe:U))]}function rt(){let e=i.saved,t=(i.setup?.devices??[]).some(o=>e.includes(o.name)&&o.needsRestart);return[r("header",{},r("h1",{},e.length===1?`${e[0]} is set up`:`${e.length} devices are set up`)),r("p",{class:"lead"},"They now appear in the Matter apps paired with Matterbridge. If Matterbridge is not paired yet, pair it from its home page."),t?r("p",{class:"help"},r("strong",{},et)):null,r("p",{class:"help"},$e),r("div",{class:"footer"},$("Done",U,"primary"))]}function ot(e){return!e.isConfigured&&(e.support==="supported"||e.support==="unknownProduct")}function Vt(e){let t=[];return e.isConfigured&&t.push("Already set up."),e.support==="unknownProduct"&&t.push("The catalog does not list its product: the plugin checks its data points in the next step."),e.support==="otherKind"&&t.push("A kind of device the plugin does not control yet, such as a fan: only lights, switches, plugs and sensors for now."),e.support==="gateway"&&t.push("A gateway: the devices behind it are listed on their own."),e.support==="gateway"||e.support==="otherKind"||(e.online||t.push("The Tuya cloud says it is offline."),e.gatewayId!==void 0&&t.push("Behind a gateway."),e.lan!==void 0&&t.push(`Heard on your network at ${e.lan.host}.`),e.hasLocalKey||t.push("No local key from the cloud: reached through the cloud only.")),t}function Jt(e){let t=ot(e),o=`device-${e.deviceId}`,u=r("input",{type:"checkbox",id:o,checked:t&&i.selected.has(e.deviceId),disabled:!t,onchange:()=>{u.checked?i.selected.add(e.deviceId):i.selected.delete(e.deviceId),D()}});return r("li",{class:t?"found":"found unavailable"},r("label",{for:o},u,r("span",{},r("strong",{},e.name),r("span",{class:"meta"},` ${e.deviceId}, product ${e.productKey}${e.category===""?"":`, category ${e.category}`}`),...Vt(e).map(m=>r("span",{class:"meta note"},m)))))}function it(){let e=i.devices.filter(o=>i.selected.has(o.deviceId)&&ot(o)),t=e.length===1?"Set up 1 device":`Set up ${e.length} devices`;return[ae(),r("header",{},r("h1",{},"Your Tuya devices")),V(),i.devices.length>0?r("ul",{class:"found-list"},...i.devices.map(Jt)):null,!i.isBusy&&i.devices.length===0&&i.error===""?r("p",{class:"empty"},"Your Tuya account has no device yet. Add your devices in the Smart Life app, then read the list again."):null,r("div",{class:"footer"},$("Read the list again",()=>{se()}),$("Cancel",U),$(t,()=>Se(Qe(e)),"primary",e.length===0))]}function st(e,t){return e.color===void 0?!1:e.mode===void 0?e.brightness===void 0:t[e.component]?.[e.mode.control]===e.mode.color}function at(e,t){return t&&e.color?.brightness!==void 0?e.color.brightness:e.brightness??e.color?.brightness}function ut(e,t){if(t.unitFrom===void 0)return t.unit;let o=e[t.component]?.[t.unitFrom];return typeof o=="string"?o:t.unit}function ue(e,t){return e[t.component]?.[t.control]}function Wt(e,t,o){if(e.kind==="temperature"){let m=ut(o,e);return`${String(t)} \xB0${m!==void 0&&/^f/i.test(m)?"F":"C"}`}if(e.kind==="humidity")return`${String(t)} % humidity`;if(e.kind==="illuminance")return`${String(t)} lx`;let u=t===!0||t===1||t==="true";return e.kind==="occupancy"?u?"Motion":"No motion":e.kind==="contact"?u?"Open":"Closed":u?"Water leak":"No leak"}function ke(e,t){if(e===void 0||t===void 0)return"";let o=[];for(let h of e.lights){let A=ue(t,h);if(typeof A!="boolean")continue;let L=e.lights.length===1?A?"On":"Off":`${h.label} ${A?"on":"off"}`,N=at(h,st(h,t)),j=N===void 0?void 0:ue(t,{component:h.component,control:N.control}),G=N!==void 0&&typeof j=="number"?Math.round((j-N.min)/(N.max-N.min)*100):void 0;o.push(G===void 0||!A?L:`${L} at ${Math.max(G,1)} %`)}let u=e.outlets.length===1;for(let h of e.outlets){let A=ue(t,h);typeof A=="boolean"&&o.push(u?A?"On":"Off":`${h.label} ${A?"on":"off"}`)}for(let h of e.sensors){let A=ue(t,h);A!==void 0&&o.push(Wt(h,A,t))}let{meter:m}=e;for(let h of[m?.power,m?.voltage,m?.current,m?.energy]){if(h===void 0)continue;let A=ue(t,h);typeof A=="number"&&o.push(`${A} ${h.unit}`)}if(e.battery!==void 0){let h=ue(t,e.battery);typeof h=="number"&&o.push(`battery ${h} %`)}return o.join(", ")}function pe(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function Gt(e){let{features:t}=e;if(t===void 0)return"as it was set up";let o=re(t),u=P=>P!==o&&!e.hiddenFeatures.includes(P),m=t.lights.filter(P=>u(P.id)).map(P=>P.label),h=t.outlets.filter(P=>u(P.id)).map(P=>P.label),A=t.sensors.filter(P=>u(P.id)).map(P=>P.label.toLowerCase()),L=t.settingSwitches.filter(P=>e.addedFeatures.includes(P.id)).map(P=>P.label.toLowerCase()),N=`a ${t.sensors[0]?.label.toLowerCase()??""} sensor`;t.lights.length>0?N="a light":t.outlets.length>0&&(N="an outlet");let j=[N];m.length>0&&j.push(pe(m)),h.length>0&&j.push(pe(h)),fe(t)&&!e.hiddenFeatures.includes(le)&&j.push("the meter"),A.length>0&&j.push(`a sensor for the ${pe(A)}`),L.length>0&&j.push(`a switch for the ${pe(L)}`),t.battery!==void 0&&j.push("its battery");let G=j.length>1||m.length>1||h.length>1;return`${pe(j)}${G?e.isComposed?", all as one device":", each a device of its own":""}`}var Yt={lan:" on your network",cloud:" through the Tuya cloud"};function Zt(e){return e.status!=="online"||e.route!=="cloud"||e.isCloudOnly===!0?null:e.hasLan?r("p",{class:"meta"},"It did not answer on your network, so the plugin reaches it through the Tuya cloud."):r("p",{class:"meta"},"It was not heard on your network, so the plugin reaches it through the Tuya cloud. Where the plugin cannot hear it, such as on another subnet, enter its IP address in its options.")}function Xt(e){let o={online:`Online${e.route===void 0?"":Yt[e.route]}`,connecting:"Connecting\u2026",offline:"Not answering",stopped:"Not started"}[e.status],u=i.confirmingRemoval===e.deviceId,m=e.productName??`product ${e.productKey}`,h=e.status==="online"?ke(e.features,e.values):"";return r("li",{class:"device"},r("div",{class:"device-main"},r("h3",{},e.name),r("p",{class:"meta"},r("span",{class:`status ${e.status}`},o),` ${m}, ${e.deviceId}. In Matter: ${Gt(e)}.`),h===""?null:r("p",{class:"meta readings"},`${h}.`),Zt(e),e.status!=="online"&&e.error?r("p",{class:"meta problem-text"},e.error):null,e.needsRestart?r("p",{class:"meta"},r("strong",{},"Restart Matterbridge")," to apply the new options in Matter. Until then it keeps its current endpoints."):null),u?r("div",{class:"actions"},r("span",{class:"meta"},"Remove it from Matter too?"),$("Remove",()=>{tt(e)},"danger"),$("Keep",()=>{i.confirmingRemoval="",D()})):r("div",{class:"actions"},e.features===void 0?$("Set up again",()=>Se([ye(e)]),"quiet",i.setup?.account===void 0):$("Options",()=>Ye(e),"quiet"),e.features!==void 0&&(e.status==="offline"||e.status==="stopped")?$("Reconnect",()=>{Ze(e)},"quiet"):null,$("Remove",()=>{i.confirmingRemoval=e.deviceId,D()})))}function zt(){let e=i.setup?.account;if(i.setup===void 0)return null;if(e===void 0)return r("section",{class:"account"},r("p",{class:"notice problem",role:"alert"},"No Tuya account is signed in. The devices below stay in Matter and are reached on your network alone, and new devices cannot be added, until you sign in."),$("Sign in",ie,"primary"));let t=e.type==="smartLife"?`Signed in with the Smart Life app (User Code ${e.userCode}).`:`Signed in to the Tuya developer platform (project ${e.accessId}, data center ${de[e.dataCenter]}).`,o=i.confirmingSignOut?[r("span",{class:"meta"},"The devices stay in Matter, and keep working on your network."),$("Sign out",()=>{Ge()},"danger"),$("Stay signed in",()=>{i.confirmingSignOut=!1,D()})]:[$(e.needsSignIn?"Sign in again":"Switch account",ie,e.needsSignIn?"primary":"quiet"),$("Sign out",()=>{i.confirmingSignOut=!0,D()})];return r("section",{class:"account"},r("p",{class:"meta"},t),e.needsSignIn?r("p",{class:"notice problem",role:"alert"},"The Tuya cloud no longer accepts this sign in. Sign in again to keep the devices reachable through the cloud and to add more."):null,r("div",{class:"actions"},...o))}function en(){let e=i.setup?.discoveryError;return e===void 0?null:r("p",{class:"notice problem",role:"alert"},`The plugin does not listen for devices on your network, so it reaches them through the Tuya cloud, or at the host given in their options: ${e}`)}function ct(){let e=i.setup?.devices??[],t=i.setup?.account!==void 0&&!i.setup.account.needsSignIn;return[r("header",{},r("h1",{},"Tuya devices"),t?$("Add devices",()=>{se()},"primary"):null),V(),zt(),en(),e.length===0&&i.setup?r("p",{class:"empty"},"No device is set up yet. Add one to control it from Matter."):r("ul",{class:"devices"},...e.map(Xt)),i.setup?null:$("Try again",()=>{be()},"primary")]}var tn={temperature:"temperature sensor",humidity:"humidity sensor",illuminance:"light sensor",occupancy:"motion sensor",contact:"contact sensor",waterLeak:"water leak detector"};function ce(e,t,o,u,m){let h=r("input",{type:"checkbox",id:e,checked:t,onchange:()=>m(h.checked)});return r("label",{class:"choice",for:e},h,r("span",{},r("strong",{},o),r("span",{class:"meta"},u)))}function dt(e,t,o,u,m,h){let A=`${e}-${t}`,L=r("input",{type:"radio",name:e,id:A,checked:t===o,onchange:()=>h(t)});return r("label",{class:"choice",for:A},L,r("span",{},r("strong",{},u),r("span",{class:"meta"},m)))}function Ie(e,t){return e.isComposed?`It appears as a part of "${e.name}", tagged "${t}".`:`It appears as "${e.name} ${t}".`}function he(e,t,o){let u=e.filter(m=>m!==t);return o?[...u,t]:u}function nn(e){let t=r("input",{type:"text",id:"device-name",value:e.name,maxLength:32,autocomplete:"off",spellcheck:!1});t.addEventListener("input",m=>{e.name=t.value.trim(),m.isComposing||D()});let o=e.device.cloudName,u=o===void 0?"":`Its name in the Smart Life app is "${o}". `;return r("section",{},r("h2",{},r("label",{for:"device-name"},"Name in Matter")),r("p",{class:"help"},`${u}The name here is what your Matter apps show, up to 32 characters, and no two devices of this plugin share one. A new name in the Smart Life app does not change it.`),r("div",{class:"inline-form"},t))}function rn(e,t){let o=re(t),u=[...t.lights,...t.outlets,...t.sensors].find(L=>L.id===o),m=[];for(let L of t.lights)L.id!==o&&m.push(ce(`feature-${L.id}`,!e.hiddenFeatures.includes(L.id),L.label,`A light. ${Ie(e,L.label)}`,N=>{e.hiddenFeatures=he(e.hiddenFeatures,L.id,!N),D()}));for(let L of t.outlets)L.id!==o&&m.push(ce(`feature-${L.id}`,!e.hiddenFeatures.includes(L.id),L.label,`An on/off outlet. ${Ie(e,L.label)}`,N=>{e.hiddenFeatures=he(e.hiddenFeatures,L.id,!N),D()}));let{meter:h}=t;if(h!==void 0&&fe(t)){let L=[h.power&&"power",h.voltage&&"voltage",h.current&&"current",h.energy&&"energy used"].filter(N=>typeof N=="string");m.push(ce("feature-meter",!e.hiddenFeatures.includes(le),"Meter",`The ${L.join(", ")} of "${e.name}", which few Matter apps show yet: Home Assistant does.`,N=>{e.hiddenFeatures=he(e.hiddenFeatures,le,!N),D()}))}for(let L of t.sensors)L.id!==o&&m.push(ce(`feature-${L.id}`,!e.hiddenFeatures.includes(L.id),L.label,`A ${tn[L.kind]}. ${Ie(e,L.label)}`,N=>{e.hiddenFeatures=he(e.hiddenFeatures,L.id,!N),D()}));for(let L of t.settingSwitches)m.push(ce(`feature-${L.id}`,e.addedFeatures.includes(L.id),L.label,`A switch for a setting of the device. ${Ie(e,L.label)}`,N=>{e.addedFeatures=he(e.addedFeatures,L.id,N),D()}));let A=u===void 0?"":`${u.label} is the device itself in Matter, and always appears there. `;return r("section",{},r("h2",{},"What appears in Matter"),r("p",{class:"help"},m.length===0?`${A}The device has nothing else to show.`:`${A}Choose what else appears with it.`),m.length===0?null:r("div",{class:"choices"},...m))}function on(e){return r("section",{},r("h2",{},"One device or several"),r("p",{class:"help"},"The other lights, the outlets, the sensors and the switches can be parts of the device in Matter, or devices of their own beside it."),r("div",{class:"choices"},ce("composed",e.isComposed,"Show it as one device",`Your Matter app has one device, "${e.name}", and its parts move between rooms with it. A part has no name of its own in Matter, so an app may show the outlets as numbered outlets, and an app that shows no parts shows the device alone. Turned off, each is a device of its own with its own name, which your app puts in a room by itself.`,t=>{e.isComposed=t,D()})))}function sn(e){let t=r("input",{type:"text",id:"device-host",value:e.host,placeholder:"Leave empty to find it on your network",maxLength:253,autocomplete:"off",spellcheck:!1});t.addEventListener("input",()=>{e.host=t.value.trim()});let o=r("select",{id:"device-version",onchange:()=>{e.version=o.value}},r("option",{value:"",selected:e.version===""},"Not set"),...He.map(u=>r("option",{value:u,selected:u===e.version},u)));return r("div",{class:"field"},r("label",{for:"device-host"},"IP address or host name (optional)"),r("p",{class:"help"},"Most devices need neither of these: leave both empty, and the plugin finds the device by the broadcasts it sends. Only where it does not hear the device on your network, such as on another subnet or in a Docker container without host networking, enter its IP address, ideally one your router keeps for it, and the protocol version it speaks, which the Smart Life app does not show: tinytuya or tuya-local tell it. For a device behind a gateway, enter those of the gateway."),r("div",{class:"inline-form"},t),r("label",{for:"device-version"},"Protocol version (only with an IP address or host name)"),o)}function an(e){let t=h=>{e.isCloudOnly=h==="cloud",D()},o=e.isCloudOnly?"cloud":"lan",u=e.probe?.route,m="";return u==="lan"?m=" It answered on your network just now.":u==="cloud"&&(m=" It answered through the Tuya cloud just now: the plugin switches to your network once it hears the device there."),r("section",{},r("h2",{id:"connection-title"},"Connection"),r("p",{class:"help"},`How the plugin reaches the device.${m}`),r("div",{class:"choices",role:"radiogroup","aria-labelledby":"connection-title"},dt("connection","lan",o,"On your network first, through the Tuya cloud otherwise","The plugin hears the device on your network by the broadcasts it sends, and follows it to a new IP address. It keeps working while the Tuya cloud or the internet is down.",t),dt("connection","cloud",o,"Through the Tuya cloud only","For a device that is not on the network of Matterbridge.",t)),e.isCloudOnly?null:sn(e))}function lt(){let e=W();if(e===void 0)return[V()];let t=e.features??{lights:[],outlets:[],settingSwitches:[],sensors:[]},o=ke(e.features,e.values);return[ae(),Ce(),Te(e,`Options for the ${me(e.device,e.productName)}.`),o===""?null:r("p",{class:"meta readings"},`It reports: ${o}.`),nn(e),rn(e,t),on(e),an(e),e.isNew?null:r("p",{class:"help"},"Changing what appears in Matter, or whether it is one device, takes effect at the next restart of Matterbridge, which this page and Matterbridge ask for. Until then the device keeps its current endpoints. The name and the connection change at once."),V(),r("div",{class:"footer"},$("Cancel",U),$(e.isNew?`Add ${e.name}`:"Save options",()=>{ze(e)},"primary"))]}var mt=Bt(gt(),1);function vt(e){let t=(0,mt.default)(0,"M");return t.addData(e),t.make(),r("div",{class:"qr",role:"img","aria-label":"QR code to scan with the Smart Life app",html:t.createSvgTag({cellSize:4,margin:2,scalable:!0})})}function yt(e,t,o){let u=`method-${e}`,m=r("input",{type:"radio",name:"method",id:u,checked:i.signIn.method===e,onchange:()=>{i.signIn.method=e,i.error="",D()}});return r("label",{class:"choice",for:u},m,r("span",{},r("strong",{},t),r("span",{class:"meta"},o)))}function un(){return r("section",{},r("h2",{id:"method-title"},"How to sign in"),r("div",{class:"choices",role:"radiogroup","aria-labelledby":"method-title"},yt("smartLife","With the Smart Life app (recommended)","Scan a QR code with the Smart Life or Tuya Smart app your devices are in. Nothing to set up first."),yt("developer","With a cloud project of the Tuya developer platform","For a project you made on platform.tuya.com, with your app account linked to it. Its IoT Core trial has to be extended from time to time.")))}function cn(){let e=r("input",{type:"text",id:"user-code",value:i.signIn.userCode,maxLength:32,autocomplete:"off",spellcheck:!1}),t=()=>{let o=e.value.trim();o!==""&&Ue(o)};return e.addEventListener("keydown",o=>{o.key==="Enter"&&t()}),[r("div",{class:"field"},r("label",{for:"user-code"},"User Code"),r("p",{class:"help"},"In the Smart Life app, open Me, then the settings, then Account and Security: the User Code is listed there. It is case-sensitive."),r("div",{class:"inline-form"},e)),r("div",{class:"footer"},$("Cancel",U),$("Show the QR code",t,"primary"))]}function dn(e){return[r("p",{class:"lead"},"In the Smart Life app, tap the scan icon at the top of the home tab, scan this code, and confirm the sign in in the app."),vt(e),r("p",{class:"notice working",role:"status"},r("span",{class:"spinner"}),"Waiting for the app to confirm\u2026"),r("p",{class:"help"},"The plugin signs in as Home Assistant does, so the app may name Home Assistant. The code stays valid for a few minutes."),r("div",{class:"footer"},$("Cancel",()=>{Je()}))]}function ln(){let{login:e}=i;if(e.status==="waiting"&&e.qrCode!==void 0)return dn(e.qrCode);let t=e.status==="expired"?"The QR code was not scanned in time. Show a new one to try again.":e.status==="failed"?`The sign in did not work: ${e.message??"unknown"}`:"";return[t===""?null:r("p",{class:"notice problem",role:"alert"},t),...cn()]}function fn(){let e=r("input",{type:"text",id:"access-id",value:i.signIn.accessId,maxLength:128,autocomplete:"username",spellcheck:!1}),t=r("input",{type:"password",id:"access-secret",maxLength:128,autocomplete:"current-password"}),o=r("select",{id:"data-center"},...Object.keys(de).map(m=>r("option",{value:m,selected:m===i.signIn.dataCenter},`${de[m]} (${m})`))),u=()=>{e.value.trim()===""||t.value.trim()===""||We(e.value.trim(),t.value.trim(),o.value)};return t.addEventListener("keydown",m=>{m.key==="Enter"&&u()}),[r("p",{class:"help"},"The cloud project needs your Smart Life account linked to it, under Devices > Link App Account, and the IoT Core service. Its Access ID and Access Secret are on its overview page."),r("div",{class:"field"},r("label",{for:"access-id"},"Access ID"),e),r("div",{class:"field"},r("label",{for:"access-secret"},"Access Secret"),r("p",{class:"help"},"It is kept in the configuration of the plugin."),t),r("div",{class:"field"},r("label",{for:"data-center"},"Data center"),r("p",{class:"help"},"The data center of your app account, which the project lists under Devices."),o),r("div",{class:"footer"},$("Cancel",U),$("Sign in",u,"primary"))]}function wt(){let e=i.setup?.account!==void 0,t=i.login.status==="waiting";return[r("header",{},r("h1",{},e?"Sign in to Tuya again":"Sign in to Tuya")),r("p",{class:"lead"},"The plugin lists your devices and gets the key each one encrypts its traffic with from the Tuya cloud, then reaches them on your network first. Your password is never asked for."),V(),t?null:un(),...i.signIn.method==="smartLife"?ln():fn()]}function bt(){try{if(window.parent===window)return;let e=getComputedStyle(window.parent.document.body);for(let t of["--primary-color","--div-bg-color","--div-text-color","--main-bg-color","--main-label-color","--div-border-color","--main-light-color"]){let o=e.getPropertyValue(t).trim();o!==""&&document.documentElement.style.setProperty(`--host${t.slice(1)}`,o)}document.documentElement.style.setProperty("--host-font",e.fontFamily)}catch{}}Ke({loading:()=>[r("p",{class:"notice working",role:"status"},r("span",{class:"spinner"}),"Loading\u2026")],home:ct,signIn:wt,find:it,connect:nt,options:lt,done:rt});bt();D();be();
|
|
4
4
|
/**
|
|
5
5
|
* @file apps/frontend/src/api.ts
|
|
6
6
|
* @description What the plugin's API sends and takes, and the call to it: see src/setup/setupApi.ts in the plugin.
|
|
@@ -222,6 +222,28 @@ var kt=Object.create;var _e=Object.defineProperty;var It=Object.getOwnPropertyDe
|
|
|
222
222
|
* See the License for the specific language governing permissions and
|
|
223
223
|
* limitations under the License.
|
|
224
224
|
*/
|
|
225
|
+
/**
|
|
226
|
+
* @file src/lightState.ts
|
|
227
|
+
* @description This file contains which of its brightnesses a light shows, which Matter and the setup page share.
|
|
228
|
+
* @author Calvin Che
|
|
229
|
+
* @created 2026-11-02
|
|
230
|
+
* @version 1.0.0
|
|
231
|
+
* @license Apache-2.0
|
|
232
|
+
*
|
|
233
|
+
* Copyright 2026 Calvin Che.
|
|
234
|
+
*
|
|
235
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
236
|
+
* you may not use this file except in compliance with the License.
|
|
237
|
+
* You may obtain a copy of the License at
|
|
238
|
+
*
|
|
239
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
240
|
+
*
|
|
241
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
242
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
243
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
244
|
+
* See the License for the specific language governing permissions and
|
|
245
|
+
* limitations under the License.
|
|
246
|
+
*/
|
|
225
247
|
/**
|
|
226
248
|
* @file src/temperatureUnit.ts
|
|
227
249
|
* @description This file contains how the unit of a temperature is read, which Matter and the setup page share.
|