function stringFromUTF8Array(e){for(var t=[1,1,1,1,2,2,3,0],i=e.length,r="",n=0;n>3&7];if(!(64&a)||!s||n+s>i)return null;for(a&=63>>s;s>0;s-=1){var o=e[n++];if(128!=(192&o))return null;a=a<<6|63&o}}r+=String.fromCharCode(a)}return r}function BitExtract(e){this.data=e,this.offset=0}function BinaryExtract(e){this.buffer=e,this.offset=0}function pad(e,t){for(var i=""+e;i.length>1&15).toString():"dali_single_"+(e>>1&63).toString()}function profileParserPartial(e,t,i){var r=e.getUint8();t.profile_id=255===r?"no_profile":r;var n;n=e.getUint8();var a=e.getUint8();t.address=addressParse(a,"all_devices",i);var s=new BitExtract(e.getUint8()),o=[];return s.getBits(1)&&o.push("holiday"),s.getBits(1)&&o.push("mon"),s.getBits(1)&&o.push("tue"),s.getBits(1)&&o.push("wed"),s.getBits(1)&&o.push("thu"),s.getBits(1)&&o.push("fri"),s.getBits(1)&&o.push("sat"),s.getBits(1)&&o.push("sun"),t.days_active=o,e.getUint8(),n}function decodeUnixEpoch(e,t){var i=new Date(1e3*e).toISOString();return e<1420070400&&(i="invalid_timestamp",t.warnings.push("invalid_timestamp")),i}function decodeLdrConfig(e,t){t.packet_type="deprecated_ldr_input_config_packet";var i=e.getUint8();t.ldr_off_threshold_high=255===i?"disabled":i;var r=e.getUint8();t.ldr_on_threshold_low=255===r?"disabled":r;var n=e.getUint8Bits();n.getBits(2),t.trigger_alert_enabled=n.getBits(1)}function decodeLightDimStep(e){var t={},i=e.getFloat(),r=e.getUint8();return t.light_level__lx=formatLightLx(i),t.dimming_level__percent=decodeDimmingLevel(r,"inactive"),t}function decodeLightSensorConfig(e,t,i){if(t.packet_type="light_sensor_config_packet",255!==e.getUint8()){var r=e.getUint8Bits();for(t.notification_on_every_step=r.getBits(1),t.light_sensor_clamps_profile=r.getBits(1),t.light_sensor_clamps_dig=r.getBits(1),t.interpolate_steps=r.getBits(1),t.measurement_duration__s=e.getUint8(),t.address=addressParse(e.getUint8(),"all_devices",i),t.dim_steps=[];e.availableLen();)t.dim_steps.push(decodeLightDimStep(e))}}function decodeDimNotifyConfig(e,t,i){t.packet_type="dim_notify_config_packet";var r=e.getUint8();t.random_delay__s=255===r?"disabled":5*r,t.packet_limit__s=60*e.getUint8()}function decodeInterfaceType(e,t){switch(e){case 0:return"dali";case 1:return"analog_0_10v";case 254:return t.errors.push("not_supported"),"not_supported";case 254:return"factory_default";default:return t.errors.push("invalid_value"),"invalid_value"}}function decodeInterfaceTypeConfig(e,t,i){t.packet_type="interface_type_config_packet",t.interface_type=decodeInterfaceType(e.getUint8(),i)}function decodeDimmingLevel(e,t){return 255===e?t:e}function decodeDigConfig(e,t,i){t.packet_type="deprecated_dig_input_config_packet";var r=e.getUint16();t.light_on_duration__s=65535===r?"dig_input_disabled":r;var n=e.getUint8Bits();n.getBits(1),t.signal_edge_rising=n.getBits(1),t.trigger_alert_enabled=n.getBits(1),t.address=addressParse(e.getUint8(),"all_devices",i),t.dimming_level__percent=decodeDimmingLevel(e.getUint8(),"disabled")}function decodeDigInputConfigNew(e,t,i){t.packet_type="dig_input_config_packet";var r=e.getUint8();if(255!==r){t.dig_enabled=r;var n=e.getUint8Bits();t.dig_mode_button=n.getBits(1),t.polarity_high_or_rising=n.getBits(1),t.notification_on_activation=n.getBits(1),t.notification_on_inactivation=n.getBits(1),n.getBits(3),t.source_d4i_motion_sensor=n.getBits(1),t.address=addressParse(e.getUint8(),"all_devices",i),t.active_dimming_level__percent=decodeDimmingLevel(e.getUint8(),"inactive"),t.inactive_dimming_level__percent=decodeDimmingLevel(e.getUint8(),"inactive");var a=e.getUint16(),s=e.getUint16();t.on_delay__s=a,t.off_delay__s=s}}function decodeStepTime(e){var t=10*e,i=Math.trunc(t/60),r=t-60*i;return pad(i,2)+":"+pad(r,2)}function decodeOdRelaySwStep(e){var t={};t.step_time=decodeStepTime(e.getUint8());var i=0!==e.getUint8();return t.open_drain_output_on=i,t}function decodeZenithStep(e){var t={};t.zenith_angle__deg=(e.getInt8()/6+90).toFixed(2);var i=e.getUint8();return t.dimming_level__percent=decodeDimmingLevel(i,"disabled"),t}function decodeCalendarConfigV11(e,t){t.packet_type="calendar_config_packet";var i=e.getUint8Bits(),r=i.getBits(4),n=i.getBits(4),a=e.getUint8Bits();t.calendar_prefers_meta_pos=a.getBits(1),t.calendar_clamps_profiles=a.getBits(1),t.calendar_clamps_dig=a.getBits(1),t.ignore_gnss=a.getBits(1),t.latitude__deg=e.getInt16()/100,t.longitude__deg=e.getInt16()/100,t.sunrise_steps=[],t.sunset_steps=[];for(var s=0;s=16?(t.errors.push("invalid_fade"),"invalid_fade"):[.5,.71,1,1.41,2,2.83,4,5.66,8,11.31,16,22.63,32,45.25,64,90.51][e]}function decodeLocationConfigV11(e,t){t.packet_type="location_config_packet";var i=e.getUint8();t.latitude__deg=e.getInt32()/1e7,t.longitude__deg=e.getInt32()/1e7,t.address=e.getTextUtf8(i)}function decodeLumalinkMode(e,t){switch(e){case 0:return"never_advertise";case 1:return"first_commission";case 2:return"every_boot";case 3:return"always";default:return t.errors.push("invalid_mode"),"invalid_mode"}}function decodeLumalinkConfig(e,t,i){t.packet_type="lumalink_config_packet",t.access_mode=decodeLumalinkMode(e.getUint8(),i)}function decodeLedConfig(e,t){t.packet_type="onboard_led_config_packet";var i=e.getUint8Bits().getBits(1);t.status_led_enabled=i}function alertParamConfig(e,t){return e===t?"alert_off":e}function decodeMeteringAlertConfig(e,t,i){if(t.packet_type="metering_alert_config_packet",1===e.getUint8()){var r=e.getUint16(),n=e.getUint16(),a=e.getUint16(),s=e.getUint16(),o=e.getUint8();t.min_power__W=alertParamConfig(r,65535),t.max_power__W=alertParamConfig(n,65535),t.min_voltage__V=alertParamConfig(a,65535),t.max_voltage__V=alertParamConfig(s,65535),t.min_power_factor=255===o?"alert_off":o/100}else i.errors.push("invalid_packet_type")}function decodeFadeConfig(e,t,i){t.packet_type="fade_config_packet",t.fade_duration__s=decodeFade(e.getUint8(),i)}function decodeMulticastConfig(e,t,i){t.packet_type="multicast_config_packet";var r=e.getUint8();r>3?i.errors.push("invalid_multicast_device"):(t.multicast_device=r,t.devaddr=bytesToHexStr(e.getRaw(4).reverse()),t.nwkskey=bytesToHexStr(e.getRaw(16)),t.appskey=bytesToHexStr(e.getRaw(16)))}function decodeClearConfig(e,t,i){switch(t.packet_type="clear_config_packet",e.getUint8()){case 33:t.reset_target="profile_config",t.address=addressParse(e.getUint8(),"all_profiles",i);break;case 35:t.reset_target="holiday_config";break;case 40:t.reset_target="dig_input_config";break;case 41:t.reset_target="light_sensor_config";break;case 82:t.reset_target="multicast_config";var r=e.getUint8();t.multicast_device=255===r?"all_multicast_devices":"multicast_device_"+r;break;case 255:t.reset_target="factory_reset",t.device_serial=intToHexStr(e.getUint32(),8);break;default:i.errors.push("invalid_clear_config_target")}}function decodeFport50(e,t,i){switch(e.getUint8()){case 1:return void decodeLdrConfig(e,t);case 3:return void decodeDigConfig(e,t,i);case 5:for(t.packet_type="open_drain_output_config_packet",t.switching_steps=[];e.availableLen();)t.switching_steps.push(decodeOdRelaySwStep(e));return;case 7:return void decodeStatusConfig(e,t);case 9:return void decodeTimeConfig(e,t,i);case 11:return void decodeUsageConfig(e,t);case 13:return void decodeBootDelayConfig(e,t);case 21:return void decodeLedConfig(e,t);case 22:return void decodeMeteringAlertConfig(e,t,i);case 82:return void decodeMulticastConfig(e,t,i);case 255:return void decodeClearConfig(e,t,i);case 32:return void decodeCalendarConfigV11(e,t);case 33:return void decodeProfileConfig(e,t,i);case 34:return void decodeFadeConfig(e,t,i);case 35:return void decodeHolidayConfig(e,t);case 36:return void decodeDaliMonitorConfig(e,t);case 37:return void decodeFallbackDimConfig(e,t);case 38:return void decodeLocationConfigV11(e,t);case 39:return void decodeLumalinkConfig(e,t,i);case 40:return void decodeDigInputConfigNew(e,t,i);case 41:return void decodeLightSensorConfig(e,t,i);case 42:return void decodeDimNotifyConfig(e,t);case 43:return void decodeInterfaceTypeConfig(e,t,i);case 83:return void decodeMulticastFcntConfig(e,t);case 254:for(t.packet_type="chained_config_packet",t.payloads=[];e.availableLen();){var r={};decodeFport50(e,r,i),t.payloads.push(r)}return;default:i.errors.push("invalid_packet_type")}}function daliStatus(e,t,i){var r={driver_error:!1,lamp_failure:!1,lamp_on:!1,limit_error:!1,fade_running:!1,reset_state:!1,missing_short_address:!1,power_failure:!1};if(255===e.data)return r;var n=e.getBits(1);r.driver_error=n;var a=e.getBits(1);r.lamp_failure=a,r.lamp_on=e.getBits(1);var s=e.getBits(1);r.limit_error=s,r.fade_running=e.getBits(1);var o=e.getBits(1);r.reset_state=o;var _=e.getBits(1);r.missing_short_address=_;var d=e.getBits(1);return r.power_failure=d,n&&i.warnings.push(t+" driver_error"),a&&i.warnings.push(t+" lamp_failure"),s&&i.warnings.push(t+" limit_error"),o&&i.warnings.push(t+" reset_state"),d&&i.warnings.push(t+" power_failure"),r}function tiltSensorAlerts(e,t,i){if(255===e.data)return t;var r=[];return e.getBits(1)&&r.push("data_ok"),e.getBits(1)&&r.push("motion_in_15s"),e.getBits(1)&&r.push("motion_in_1h"),e.getBits(1)&&r.push("motion_in_24h"),e.getBits(1)&&r.push("shake_in_15s"),e.getBits(1)&&r.push("shake_in_1h"),e.getBits(1)&&r.push("shake_in_24h"),t.tilt_sensor_alerts=r,t}function decodeDaliStatus(e,t){var i={},r=addressParse(e.getUint8(),null,t);return i.address=r,i.status=daliStatus(e.getUint8Bits(),r,t),i}function decodeDimming(e,t){var i={};return i.address=addressParse(e.getUint8(),"all_devices",t),i.dimming_level__percent=decodeDimmingLevel(e.getUint8(),"resume"),i}function decodeDimmingCommand(e,t,i){for(t.packet_type="manual_dimming",t.destination=[];e.availableLen();)t.destination.push(decodeDimming(e,i))}function decodeCustomDaliReq(e,t,i){t.packet_type="custom_dali_request";var r=e.offset;if(t.query_data_raw=bytesToHexStr(e.getRaw(e.availableLen())),e.offset=r,e.availableLen()>3)e.getRaw(e.availableLen());else{var n=e.getUint8();t.address=addressParse(n,null,i),t.dali_query=e.getUint8(),1===e.availableLen()&&(t.dali_response=e.getUint8())}}function decodeCustomDaliCommand(e,t){t.packet_type="custom_dali_command",t.dali_command=bytesToHexStr(e.getRaw(e.availableLen()))}function decodeDimMap(e,t){var i={};return i.address=addressParse(e.getUint8(),null,t),i.dali_min_level=e.getUint8(),i.dali_max_level=e.getUint8(),i.dimming_curve=0===e.getUint8()?"logarithmic":"linear",i}function decodeStatusRequest(e,t,i){t.packet_type="status_usage_request";var r=e.getUint8Bits();if(t.usage_requested=r.getBits(1),t.status_requested=r.getBits(1),t.dim_map_report_requested=r.getBits(1),t.request_gnss_notification=r.getBits(1),t.dim_map_report_requested&&e.availableLen()>0)for(t.drivers=[];e.availableLen();)t.drivers.push(decodeDimMap(e,i))}function decodeDriverMemoryPartial(e,t,i){t.address=addressParse(e.getUint8(),null,i),t.memory_bank=e.getUint8(),t.memory_address=e.getUint8()}function decodeDriverMemoryPartialSized(e,t,i){decodeDriverMemoryPartial(e,t,i);var r=e.getUint8();return t.read_size__bytes=r,r}function decodeReadDriverMemory(e,t,i){if(t.packet_type="driver_memory_read",0!==e.availableLen()){var r=decodeDriverMemoryPartialSized(e,t,i);if(e.availableLen()){var n=e.getRaw(r);t.memory_value=bytesToHexStr(n)}}else i.warnings.push("driver_memory_read_failed")}function decodeWriteDriverMemory(e,t,i){t.packet_type="driver_memory_write",0!==e.availableLen()?(decodeDriverMemoryPartial(e,t),t.memory_value=bytesToHexStr(e.getRaw(e.availableLen()))):i.warnings.push("driver_memory_write_failed")}function decodeTimedDimming(e,t){var i={};return i.address=addressParse(e.getUint8(),"all_devices",t),i.dimming_level__percent=decodeDimmingLevel(e.getUint8(),"resume"),i.duration__minutes=e.getUint8(),i}function decodeTimedDimmingCommand(e,t,i){for(t.packet_type="manual_timed_dimming",t.destination=[];e.availableLen();)t.destination.push(decodeTimedDimming(e,i))}function decodeAddressDaliDriver(e,t,i){t.packet_type="address_dali_driver",t.address=addressParse(e.getUint8(),"rescan_dali_bus",i)}function decodeDaliIdentify(e){e.packet_type="dali_identify"}function decodeOpenDrainSwitching(e,t){t.packet_type="open_drain_output_control",t.open_drain_output_on=e.getUint8Bits().getBits(1)}function decodeFport60(e,t,i){switch(e.getUint8()){case 1:return void decodeDimmingCommand(e,t,i);case 3:return void decodeCustomDaliReq(e,t,i);case 4:return void decodeCustomDaliCommand(e,t);case 5:return void decodeStatusRequest(e,t,i);case 7:return void decodeReadDriverMemory(e,t,i);case 8:return void decodeWriteDriverMemory(e,t,i);case 9:return void decodeTimedDimmingCommand(e,t,i);case 12:return void decodeOpenDrainSwitching(e,t);case 10:return void decodeAddressDaliDriver(e,t,i);case 11:return void decodeDaliIdentify(t);default:i.errors.push("invalid_command")}}function dimmingSourceParser(e,t){var i={};return i.address=addressParse(e.getUint8(),null,t),i.reason=profileReason(e.getUint8(),t),i.dimming_level__percent=decodeDimmingLevel(e.getUint8(),"n/a"),i.status=daliStatus(e.getUint8Bits(),i.address,t),i}function formatLightLx(e){var t=Math.log10(e),i=t>=0?t:0,r=i>3?3:i,n=3-Math.trunc(r);return e.toFixed(n)}function calcLightLx(e){if(65535===e)return"unavailable";var t=32767&e;return formatLightLx(Math.pow(10,t/4e3)/1e3)}function decodeSensorSource(e,t,i,r){if(1===t)return i.sensor_source.ldr_input=e.getUint8(),1;if(2==t)return i.sensor_source.light_sensor__lx=calcLightLx(e.getUint16()),2;if(3==t)return i.sensor_source.d4i_light_sensor__lx=calcLightLx(e.getUint16()),2;if(4==t){var n=e.getUint8Bits();return i.sensor_source.dig_input_1_on=n.getBits(1),1}if(8==t){tilt_sensor_alerts=tiltSensorAlerts(e.getUint8Bits(),i);var a=e.getUint8();return 255==a&&(a=null),i.sensor_source.tilt_sensor__deg=a,2}return 0}function statusParser1_1(e,t,i){t.packet_type="status_packet";var r=0===(C=e.getUint8());if(r||1===C){var n=e.getUint32();t.device_unix_epoch=decodeUnixEpoch(n,i);var a={},s=e.getUint8Bits();s.getBits(1);var o=s.getBits(1),_=s.getBits(1);s.getBits(1);var d=s.getBits(1),c=s.getBits(1),u=s.getBits(1),g=s.getBits(1);if(a.dali_connection_error=o,o&&i.warnings.push("dali_connection_error"),a.metering_com_error=c,c&&i.warnings.push("metering_com_error"),a.ext_rtc_warning=u,u&&i.warnings.push("ext_rtc_warning"),a.internal_relay_closed=g,r&&(a.ldr_input_on=_,a.dig_input_on=d),!r){var l=e.getUint8Bits();l.getBits(1),l.getBits(1),a.open_drain_output_on=l.getBits(1),l.getBits(1),l.getBits(1),l.getBits(1),a.lumalink_connected=l.getBits(1),a.lumalink_connected_after_boot=l.getBits(1)}t.status=a,t.downlink_rssi__dBm=-1*e.getUint8(),t.downlink_snr__dB=e.getInt8(),t.mcu_temperature__C=e.getInt8();var p=!0;if(r){var f=e.getUint8Bits();f.getBits(1);var v=f.getBits(1),m=f.getBits(1);f.getBits(1),t.status.open_drain_output_on=m,p=f.getBits(1),v&&(t.ldr_input_value=e.getUint8())}if(p){var h=e.getUint8Bits();h.getBits(4);var y=h.getBits(1),B=h.getBits(1),U=h.getBits(1),k=h.getBits(1),w={};w.voltage_alert_in_24h=y,w.lamp_error_alert_in_24h=B,w.power_alert_in_24h=U,w.power_factor_alert_in_24h=k,t.active_alerts=w,y&&i.warnings.push("voltage_alert_in_24h"),B&&i.warnings.push("lamp_error_alert_in_24h"),U&&i.warnings.push("power_alert_in_24h"),k&&i.warnings.push("power_factor_alert_in_24h")}if(!r){var b=e.getUint8();for(t.sensor_source={};b>0;){var C=e.getUint8();b-=1;var x=decodeSensorSource(e,C,t);0==x?(i.errors.push("unsupported_sensor_source"),e.getRaw(b),b=0):b-=x}b<0&&i.errors.push("error_decoding_sensor_source")}for(t.dimming_source=[];e.availableLen();)t.dimming_source.push(dimmingSourceParser(e,i))}else i.errors.push("invalid_packet_type")}function usageConsumptionParse(e,t){var i={},r=e.getUint8();i.address=addressParse(r,"internal_measurement",t);var n=e.getUint8Bits();if(n.getBits(1)&&(i.active_energy__Wh=e.getUint32()),n.getBits(1)&&(i.active_power__W=e.getUint16()),n.getBits(1)&&(i.load_side_energy__Wh=e.getUint32()),n.getBits(1)&&(i.load_side_power__W=e.getUint16()),n.getBits(1)){var a=e.getUint8();i.power_factor=255===a?"unknown":a/100}return n.getBits(1)&&(i.mains_voltage__V=e.getUint8()),n.getBits(1)&&(i.driver_operating_time__h=Math.round(e.getUint32()/3600)),n.getBits(1)&&(i.lamp_on_time__h=Math.round(e.getUint32()/3600*10)/10),i}function usageParser(e,t,i){if(0===e.getUint8())for(t.packet_type="usage_packet",t.consumption=[];e.availableLen();)t.consumption.push(usageConsumptionParse(e,i));else i.errors.push("invalid_packet_type")}function deviceConfigParser(e,t){switch(e){case 0:return"dali";case 1:return"dali_nc";case 2:return"dali_no";case 3:return"analog_nc";case 4:return"analog_no";case 5:return"dali_analog_nc";case 6:return"dali_analog_no";case 7:return"dali_analog_nc_no";default:return t.errors.push("invalid_device_config"),"invalid_config"}}function optionalFeaturesParser(e){var t={},i=new BitExtract(e);return i.getBits(1),i.getBits(1),t.dig_input=i.getBits(1),t.ldr_input=i.getBits(1),t.open_drain_output=i.getBits(1),t.metering=i.getBits(1),i.getBits(1),i.getBits(1),t}function daliSupplyParse(e,t){if(e<112)return e;switch(e){case 126:return"bus_high";case 127:return t.warnings.push("dali_bus_error"),"bus_error";default:return"invalid_value"}}function resetReasonParse(e,t){var i=[],r=new BitExtract(e);return r.getBits(1)&&i.push("reset_0"),r.getBits(1)&&(i.push("watchdog_reset"),t.warnings.push("watchdog_reset")),r.getBits(1)&&i.push("soft_reset"),r.getBits(1)&&i.push("reset_3"),r.getBits(1)&&i.push("reset_4"),r.getBits(1)&&i.push("reset_5"),r.getBits(1)&&i.push("reset_6"),r.getBits(1)&&i.push("reset_7"),i}function bootParser(e,t,i){t.packet_type="boot_packet",t.device_serial=intToHexStr(e.getUint32(),8),t.firmware_version=e.getUint8()+"."+e.getUint8()+"."+e.getUint8(),t.device_unix_epoch=decodeUnixEpoch(e.getUint32(),i),t.device_config=deviceConfigParser(e.getUint8(),i),t.optional_features=optionalFeaturesParser(e.getUint8());var r=e.getUint8Bits();t.dali_supply_state__V=daliSupplyParse(r.getBits(7),i),t.dali_power_source_external=r.getBits(1)?"external":"internal";var n=e.getUint8Bits();t.dali_addressed_driver_count=n.getBits(7);var a=n.getBits(1);t.dali_unaddressed_driver_found=a,a&&i.warnings.push("unadressed_dali_driver_on_bus"),e.availableLen()&&(t.reset_reason=resetReasonParse(e.getUint8(),i))}function errorCodeParser(e){switch(e){case 0:case 1:return"n/a";case 2:return"unknown_fport";case 3:return"packet_size_short";case 4:return"packet_size_long";case 5:return"value_error";case 6:return"protocol_parse_error";case 7:return"reserved_flag_set";case 8:return"invalid_flag_combination";case 9:return"unavailable_feature_request";case 10:return"unsupported_header";case 11:return"unreachable_hw_request";case 12:return"address_not_available";case 13:return"internal_error";case 14:return"packet_size_error";case 129:return"profile_id_seq_error";case 130:return"profile_destination_eror";case 131:return"profile_days_error";case 132:return"profile_step_count_error";case 133:return"profile_step_value_error";case 134:return"profile_step_unsorted_error";default:return"invalid_error_code"}}function configFailedParser(e,t,i){t.packet_type="invalid_downlink_packet",t.downlink_from_fport=e.getUint8();var r=errorCodeParser(e.getUint8());t.error_reason=r,i.warnings.push("downlink_error "+r)}function decodeFport99(e,t,i){switch(e.getUint8()){case 0:return void bootParser(e,t,i);case 19:return void configFailedParser(e,t,i);default:i.errors.push("invalid_packet_type")}}function decodeFport61(e,t,i){var r=e.getUint8(),n=e.getUint8(),a=n>>4;switch(r){case 128:if(t.packet_type="dig_input_notification",2===a)t.dig_input_event_counter=e.getUint16();else if(4===a){var s=new BitExtract(n);t.dig_input_on=s.getBits(1),t.dig_input_event_counter=e.getUint32()}else i.errors.push("invalid_packet_length");return;case 129:if(t.packet_type="ldr_input_notification",2!==a)return void i.errors.push("invalid_packet_length");var o=e.getUint8Bits().getBits(1),_=e.getUint8();return t.ldr_input_on=o,void(t.ldr_input_value=_);case 131:for(t.packet_type="dali_driver_alert",t.drivers=[];e.availableLen();)t.drivers.push(decodeDaliStatus(e,i));return;case 132:t.packet_type="metering_alert";var d=new BitExtract(n),c=d.getBits(1),u=d.getBits(1),g=d.getBits(1),l=d.getBits(1),p=d.getBits(1);return t.lamp_error_alert=c,t.over_current_alert=u,t.under_voltage_alert=g,t.over_voltage_alert=l,t.low_power_factor_alert=p,c&&i.warnings.push("metering_lamp_error"),u&&i.warnings.push("metering_over_current"),g&&i.warnings.push("metering_under_voltage"),l&&i.warnings.push("metering_over_voltage"),p&&i.warnings.push("metering_low_power_factor"),t.power__W=e.getUint16(),t.voltage__V=e.getUint16(),void(t.power_factor=e.getUint8()/100);case 133:return t.packet_type="deprecated_light_sensor_notification",void(t.active_dim_step=n);case 134:t.packet_type="location_notification";var f=n;return void(0===f?(t.location_status="good_fix",t.latitude__deg=e.getFloat().toFixed(6),t.longitude__deg=e.getFloat().toFixed(6),t.last_fix_utc_time=decodeUnixEpoch(e.getUint32())):t.location_status=1===f?"no_fix":2===f||255===f?"internal_error":"invalid_status");default:i.errors.push("invalid_packet_type")}}function decodeFport49(e,t,i){switch(e.getUint8()){case 1:return void(t.packet_type="deprecated_ldr_input_config_request");case 3:return void(t.packet_type="deprecated_dig_input_config_request");case 7:return void(t.packet_type="status_config_request");case 9:return void(t.packet_type="time_config_packet");case 11:return void(t.packet_type="usage_config_request");case 13:return void(t.packet_type="boot_delay_config_request");case 21:return void(t.packet_type="onboard_led_config_request");case 22:return void(t.packet_type="metering_alert_confic_request");case 82:t.packet_type="multicast_config_request";var r=e.getUint8();return void(t.multicast_device=255===r?"all":r);case 32:return void(t.packet_type="calendar_config_request");case 33:t.packet_type="profile_config_request";var n=e.getUint8();return void(t.profile_id=255===n?"all_profiles":n);case 34:return void(t.packet_type="fade_config_request");case 35:return void(t.packet_type="holiday_config_request");case 36:return void(t.packet_type="dali_monitor_config_request");case 37:return void(t.packet_type="fallback_dim_config_request");case 38:return void(t.packet_type="location_config_request");case 39:return void(t.packet_type="lumalink_config_request");case 40:return void(t.packet_type="dig_input_config_request");case 41:return void(t.packet_type="light_input_config_request");case 42:return void(t.packet_type="dim_notify_config_request");case 43:return void(t.packet_type="interface_type_config_request");default:i.errors.push("invalid_packet_type")}}function decodeFport51(e,t,i){switch(e.getUint8()){case 255:return void(t.packet_type="activate_dfu_command");case 254:return void(t.packet_type="restart_controller_command");default:i.errors.push("invalid_command")}}function decodeByFport(e,t,i,r){var n=new BinaryExtract(t);0===n.availableLen()?r.errors.push("empty_payload"):23===e?statusParser1_1(n,i,r):26===e?usageParser(n,i,r):49===e?decodeFport49(n,i,r):50===e?decodeFport50(n,i,r):51===e?decodeFport51(n,i,r):60===e?decodeFport60(n,i,r):61===e?decodeFport61(n,i,r):99===e?decodeFport99(n,i,r):r.errors.push("invalid_fport"),0!==n.availableLen()&&r.errors.push("invalid_payload_length_long")}function decodeRaw(e,t){var i={},r={errors:[],warnings:[]};try{decodeByFport(e,t,i,r)}catch(e){r.errors.push("decoder_error "+e.message)}return{data:i,errors:r.errors,warnings:r.warnings}}function decodeDownlink(e){return decodeRaw(e.fPort,e.bytes)}function decodeUplink(e){return decodeRaw(e.fPort,e.bytes)}function Decoder(e,t){return decodeRaw(t,e)}function Decode(e,t){return decodeRaw(e,t)}BitExtract.prototype._assertOnRemainingLength=function(e){if(0===e)throw Error("invalid zero length bit field");if(this.offset+e>8)throw Error("invalid number of bits extracted")},BitExtract.prototype.getBits=function(e){this._assertOnRemainingLength(e);var t=Math.pow(2,e)-1,i=this.data>>this.offset&t;return this.offset+=e,1===e?Boolean(i):i},BinaryExtract.prototype.availableLen=function(){return this.buffer.length-this.offset},BinaryExtract.prototype._assertOnRemainingLength=function(e){if(e>this.availableLen())throw Error("invalid buffer length: too short")},BinaryExtract.prototype.getUint8=function(){return this._assertOnRemainingLength(1),this.buffer[this.offset++]},BinaryExtract.prototype.getInt8=function(){var e=this.getUint8();return e>127?e-256:e},BinaryExtract.prototype.getUint16=function(){return this._assertOnRemainingLength(2),this.buffer[this.offset++]+256*this.buffer[this.offset++]},BinaryExtract.prototype.getInt16=function(){var e=this.getUint16();return e>32767?e-65536:e},BinaryExtract.prototype.getUint24=function(){return this._assertOnRemainingLength(3),this.buffer[this.offset++]+256*this.buffer[this.offset++]+65536*this.buffer[this.offset++]},BinaryExtract.prototype.getUint32=function(){return this._assertOnRemainingLength(4),this.buffer[this.offset++]+256*this.buffer[this.offset++]+65536*this.buffer[this.offset++]+16777216*this.buffer[this.offset++]},BinaryExtract.prototype.getInt32=function(){var e=this.getUint32();return e>2147483647?e-4294967296:e},BinaryExtract.prototype.getUint64=function(){return this.getUint32()+4294967296*this.getUint32()},BinaryExtract.prototype.getTextUtf8=function(e){this._assertOnRemainingLength(e);var t=stringFromUTF8Array(this.buffer.slice(this.offset,this.offset+e));return this.offset+=e,t},BinaryExtract.prototype.getUint8Bits=function(){return new BitExtract(this.getUint8())},BinaryExtract.prototype.getRaw=function(e){this._assertOnRemainingLength(e);var t=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t},BinaryExtract.prototype.getFloat=function(){var e=this.getUint32(),t=2147483648&e?-1:1,i=(e>>23&255)-127,r=8388607&e;if(128===i)return t*(r?Number.NaN:Number.POSITIVE_INFINITY);if(-127===i){if(0===r)return 0*t;i=-126,r/=1<<22}else r=(r|1<<23)/(1<<23);return t*r*Math.pow(2,i)};