123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package temperature
- import (
- "bufio"
- "fmt"
- "strings"
- "testing"
- )
- var validStrings = []string{`{"time" : "2018-04-13 23:04:50", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}`,
- `{"time" : "2018-04-13 23:04:50", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}
- `,
- }
- var invalidStrings = []string{`sfdxcvxvczxcvzxcvzxcvzxsdfasdfasd
- sdfsdf
- sd
- f
- sdf
- sdf
- fasdfzx`, `asdfasdfavxc
- sfdsdsdf`,
- `{"timsdfe" : "2018-04-13 23:04:50", "modsdfsel" : "Acurite 606TX Sensor", "idsdf" : -5, "battsdfsdery" : "OK", "tempersdfsdature_C" : 21.800}`,
- }
- func TestValidJson(t *testing.T) {
- for _, string := range validStrings {
- reader := bufio.NewReader(strings.NewReader(string))
- parser := NewJSONParser(reader)
- measurement, err := parser.Measure()
- if err != nil {
- t.Errorf("Recieved error: %s", err)
- }
- if measurement.ID != -5 {
- t.Errorf("ID was incorrect. Expect %d but got %d", -5, measurement.ID)
- }
- }
- }
- func TestInvalidJson(t *testing.T) {
- for _, string := range invalidStrings {
- reader := bufio.NewReader(strings.NewReader(string))
- parser := NewJSONParser(reader)
- measurement, err := parser.Measure()
- if err != nil {
- t.Errorf("Invalid strings are not an error")
- }
- if measurement != nil {
- t.Errorf("There should have been no measurement for %s", string)
- }
- }
- }
- func TestRealString(t *testing.T) {
- fmt.Println("starting")
- reader := bufio.NewReader(strings.NewReader(realString))
- parser := NewJSONParser(reader)
- var measurements = make([]Measurement, 0, 100)
- for measurement, err := parser.Measure(); err == nil; measurement, err = parser.Measure() {
- if measurement != nil {
- measurements = append(measurements, *measurement)
- }
- }
- if len(measurements) != 20 {
- t.Errorf("Expected %d measurements. Got %d", 20, len(measurements))
- }
- }
- var realString = `Registering protocol [1] "Rubicson Temperature Sensor"
- Registering protocol [2] "Prologue Temperature Sensor"
- Registering protocol [3] "Waveman Switch Transmitter"
- Registering protocol [4] "LaCrosse TX Temperature / Humidity Sensor"
- Registering protocol [5] "Acurite 609TXC Temperature and Humidity Sensor"
- Registering protocol [6] "Oregon Scientific Weather Sensor"
- Registering protocol [7] "KlikAanKlikUit Wireless Switch"
- Registering protocol [8] "AlectoV1 Weather Sensor (Alecto WS3500 WS4500 Ventus W155/W044 Oregon)"
- Registering protocol [9] "Cardin S466-TX2"
- Registering protocol [10] "Fine Offset Electronics, WH2 Temperature/Humidity Sensor"
- Registering protocol [11] "Nexus Temperature & Humidity Sensor"
- Registering protocol [12] "Ambient Weather Temperature Sensor"
- Registering protocol [13] "Calibeur RF-104 Sensor"
- Registering protocol [14] "GT-WT-02 Sensor"
- Registering protocol [15] "Danfoss CFR Thermostat"
- Registering protocol [16] "Chuango Security Technology"
- Registering protocol [17] "Generic Remote SC226x EV1527"
- Registering protocol [18] "TFA-Twin-Plus-30.3049 and Ea2 BL999"
- Registering protocol [19] "Fine Offset Electronics WH1080/WH3080 Weather Station"
- Registering protocol [20] "WT450"
- Registering protocol [21] "LaCrosse WS-2310 Weather Station"
- Registering protocol [22] "Esperanza EWS"
- Registering protocol [23] "Efergy e2 classic"
- Registering protocol [24] "Generic temperature sensor 1"
- Registering protocol [25] "WG-PB12V1"
- Registering protocol [26] "HIDEKI TS04 Temperature, Humidity, Wind and Rain Sensor"
- Registering protocol [27] "Watchman Sonic / Apollo Ultrasonic / Beckett Rocket oil tank monitor"
- Registering protocol [28] "CurrentCost Current Sensor"
- Registering protocol [29] "emonTx OpenEnergyMonitor"
- Registering protocol [30] "HT680 Remote control"
- Registering protocol [31] "S3318P Temperature & Humidity Sensor"
- Registering protocol [32] "Akhan 100F14 remote keyless entry"
- Registering protocol [33] "Quhwa"
- Registering protocol [34] "OSv1 Temperature Sensor"
- Registering protocol [35] "Proove"
- Registering protocol [36] "Bresser Thermo-/Hygro-Sensor 3CH"
- Registering protocol [37] "Springfield Temperature and Soil Moisture"
- Registering protocol [38] "Oregon Scientific SL109H Remote Thermal Hygro Sensor"
- Registering protocol [39] "Acurite 606TX Temperature Sensor"
- Registering protocol [40] "TFA pool temperature sensor"
- Registering protocol [41] "Kedsum Temperature & Humidity Sensor"
- Registering protocol [42] "blyss DC5-UK-WH (433.92 MHz)"
- Registering protocol [43] "Steelmate TPMS"
- Registering protocol [44] "Schrader TPMS"
- Registering protocol [45] "Elro DB286A Doorbell"
- Registering protocol [46] "Efergy Optical"
- Registering protocol [47] "Honda Car Key"
- Registering protocol [48] "Fine Offset Electronics, XC0400"
- Registering protocol [49] "Radiohead ASK"
- Registering protocol [50] "Kerui PIR Sensor"
- Registering protocol [51] "Fine Offset WH1050 Weather Station"
- Registering protocol [52] "Honeywell Door/Window Sensor"
- Registering protocol [53] "Maverick ET-732/733 BBQ Sensor"
- Registering protocol [54] "LaCrosse TX141-Bv2/TX141TH-Bv2 sensor"
- Registering protocol [55] "Acurite 00275rm,00276rm Temp/Humidity with optional probe"
- Registering protocol [56] "LaCrosse TX35DTH-IT Temperature sensor"
- Registering protocol [57] "LaCrosse TX29IT Temperature sensor"
- Registering protocol [58] "Vaillant calorMatic 340f Central Heating Control"
- Registering protocol [59] "Fine Offset Electronics, WH25 Temperature/Humidity/Pressure Sensor"
- Registering protocol [60] "Fine Offset Electronics, WH0530 Temperature/Rain Sensor"
- Registering protocol [61] "IBIS beacon"
- Registering protocol [62] "Oil Ultrasonic STANDARD FSK"
- Registering protocol [63] "Citroen TPMS"
- Registering protocol [64] "Oil Ultrasonic STANDARD ASK"
- Registering protocol [65] "Thermopro TP11 Thermometer"
- Registering protocol [66] "Solight TE44"
- Registering protocol [67] "Wireless Smoke and Heat Detector GS 558"
- Registering protocol [68] "Generic wireless motion sensor"
- Registering protocol [69] "Toyota TPMS"
- Registering protocol [70] "Ford TPMS"
- Registering protocol [71] "Renault TPMS"
- Registering protocol [72] "FT-004-B Temperature Sensor"
- Registering protocol [73] "Ford Car Key"
- Registering protocol [74] "Philips outdoor temperature sensor"
- Registering protocol [75] "Schrader TPMS EG53MA4"
- Registering protocol [76] "Nexa"
- Registering protocol [77] "Thermopro TP12 Thermometer"
- Registering protocol [78] "GE Color Effects"
- Registering protocol [79] "X10 Security"
- Registering protocol [80] "Interlogix GE UTC Security Devices"
- Registered 80 out of 101 device decoding protocols
- Found 1 device(s)
- trying device 0: Realtek, RTL2838UHIDIR, SN: 00000001
- Found Rafael Micro R820T tuner
- Using device 0: Generic RTL2832U OEM
- Exact sample rate is: 250000.000414 Hz
- [R82XX] PLL not locked!
- Sample rate set to 250000.
- Bit detection level set to 0 (Auto).
- Tuner gain set to Auto.
- Reading samples in async mode...
- Tuned to 433920000 Hz.
- ^[ {"time" : "2018-04-13 23:00:05", "model" : "Acurite 606TX Sensor", "id" : 103, "battery" : "OK", "temperature_C" : 24.900}
- {"time" : "2018-04-13 23:00:11", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}
- {"time" : "2018-04-13 23:00:36", "model" : "Acurite 606TX Sensor", "id" : 103, "battery" : "OK", "temperature_C" : 24.900}
- {"time" : "2018-04-13 23:00:42", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}
- {"time" : "2018-04-13 23:01:07", "model" : "Acurite 606TX Sensor", "id" : 103, "battery" : "OK", "temperature_C" : 24.900}
- {"time" : "2018-04-13 23:01:13", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}
- {"time" : "2018-04-13 23:01:38", "model" : "Acurite 606TX Sensor", "id" : 103, "battery" : "OK", "temperature_C" : 24.900}
- {"time" : "2018-04-13 23:01:44", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}
- {"time" : "2018-04-13 23:02:09", "model" : "Acurite 606TX Sensor", "id" : 103, "battery" : "OK", "temperature_C" : 24.900}
- {"time" : "2018-04-13 23:02:15", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}
- {"time" : "2018-04-13 23:02:40", "model" : "Acurite 606TX Sensor", "id" : 103, "battery" : "OK", "temperature_C" : 24.800}
- {"time" : "2018-04-13 23:02:46", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}
- {"time" : "2018-04-13 23:03:11", "model" : "Acurite 606TX Sensor", "id" : 103, "battery" : "OK", "temperature_C" : 24.800}
- {"time" : "2018-04-13 23:03:17", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}
- {"time" : "2018-04-13 23:03:42", "model" : "Acurite 606TX Sensor", "id" : 103, "battery" : "OK", "temperature_C" : 24.800}
- {"time" : "2018-04-13 23:03:48", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}
- {"time" : "2018-04-13 23:04:13", "model" : "Acurite 606TX Sensor", "id" : 103, "battery" : "OK", "temperature_C" : 24.700}
- {"time" : "2018-04-13 23:04:19", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}
- {"time" : "2018-04-13 23:04:44", "model" : "Acurite 606TX Sensor", "id" : 103, "battery" : "OK", "temperature_C" : 24.700}
- {"time" : "2018-04-13 23:04:50", "model" : "Acurite 606TX Sensor", "id" : -5, "battery" : "OK", "temperature_C" : 21.800}`
|