{"record":{"id":"7ba9faff3451d678","repo":"mgth/LittleBigMouse","slug":"enter-the-four-digit-pin-displayed-by-the-hisense-device","errorCode":null,"errorMessage":"Enter the four-digit PIN displayed by the Hisense device.","messagePattern":"Enter the four-digit PIN displayed by the Hisense device\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp.Avalonia/HisenseVidaa/HisenseVidaaProtocol.cs","lineNumber":265,"sourceCode":"    ];\n\n    public static IReadOnlyList<string> LegacyResponseTopics(string deviceTopic) =>\n    [\n        $\"/remoteapp/mobile/{deviceTopic}/#\",\n        \"/remoteapp/mobile/broadcast/#\",\n    ];\n\n    public static string PairingRequestPayload() => JsonSerializer.Serialize(new\n    {\n        app_version = 2,\n        connect_result = 0,\n        device_type = \"Mobile App\",\n    });\n\n    public static string PinPayload(string pin)\n    {\n        if (pin.Length != 4 || !pin.All(char.IsAsciiDigit))\n            throw new ArgumentException(\"Enter the four-digit PIN displayed by the Hisense device.\", nameof(pin));\n        return JsonSerializer.Serialize(new { authNum = int.Parse(pin, CultureInfo.InvariantCulture) });\n    }\n\n    public static string LegacyPinPayload(string pin)\n    {\n        if (pin.Length != 4 || !pin.All(char.IsAsciiDigit))\n            throw new ArgumentException(\"Enter the four-digit PIN displayed by the Hisense device.\", nameof(pin));\n        return JsonSerializer.Serialize(new { authNum = pin });\n    }\n\n    public static string NormalizeMac(string? value, bool preserveCase = false)\n    {\n        if (string.IsNullOrWhiteSpace(value)) return \"\";\n        var compact = new string(value.Where(Uri.IsHexDigit).ToArray());\n        if (compact.Length != 12) return value.Trim();\n        var result = string.Join(':', Enumerable.Range(0, 6).Select(i => compact.Substring(i * 2, 2)));\n        return preserveCase ? result : result.ToUpperInvariant();\n    }","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/mgth/LittleBigMouse/blob/7a42f01d47d99d223b8ee33ba4019af82adf1c48/LittleBigMouse.Plugins/LittleBigMouse.Plugin.Vcp.Avalonia/HisenseVidaa/HisenseVidaaProtocol.cs#L247-L283","documentation":"PinPayload converts a 4-digit numeric PIN into the JSON pairing payload ({authNum: <int>}) for Hisense VIDAA authentication. It requires exactly 4 ASCII digits; anything else (wrong length, non-digit characters, null-ish content) throws ArgumentException so an invalid pairing code is never serialized or sent to the device.","triggerScenarios":"Calling PinPayload with a PIN string whose Length != 4, or containing non-digit characters (letters, spaces, dashes, unicode digits), e.g. PinPayload(\"12a4\"), PinPayload(\"123\"), PinPayload(\"12345\").","commonSituations":"User typing the PIN shown on the TV with a typo or trailing space; pasting a PIN that includes formatting; capturing only part of the code from the screen; binding a text field that allows arbitrary characters; confusing the new PIN payload with the legacy string variant.","solutions":["Validate that the entered PIN is exactly 4 ASCII digits (Regex ^[0-9]{4}$) before calling PinPayload.","Trim and sanitize the input field, and restrict the text box to numeric input with MaxLength=4.","Re-display the PIN on the Hisense device and have the user re-enter it.","Catch ArgumentException and show the message 'Enter the four-digit PIN displayed by the Hisense device.'"],"exampleFix":"// before\nvar payload = PinPayload(pinInput.Text); // may be \"12 4\" or \"123\"\n// after\nvar pin = pinInput.Text?.Trim() ?? \"\";\nif (System.Text.RegularExpressions.Regex.IsMatch(pin, \"^[0-9]{4}$\"))\n    var payload = PinPayload(pin);","handlingStrategy":"validation","validationCode":"public static bool IsValidPin(string? pin) =>\n    pin is not null && pin.Length == 4 && pin.All(char.IsAsciiDigit);","typeGuard":"public static bool IsFourDigitPin(string? s) => !string.IsNullOrEmpty(s) && s.Length == 4 && s.All(char.IsAsciiDigit);","tryCatchPattern":"try { var payload = HisenseVidaaProtocol.PinPayload(pin); }\ncatch (ArgumentException) { ShowError(\"Enter the four-digit PIN displayed by the Hisense device.\"); }","preventionTips":["Restrict PIN input fields to digits only with MaxLength 4.","Trim user input before validation to strip accidental whitespace.","Use Regex ^[0-9]{4}$ as the single source of truth for PIN format."],"tags":["argument-validation","pin","authentication","format-validation","hisense"],"backgroundTag":"invalid-argument-format","analyzedSha":"7a42f01d47d99d223b8ee33ba4019af82adf1c48","analyzedAt":"2026-09-16T00:35:00.514Z","contentChangedAt":"2026-09-16T00:35:00.514Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}