iqrfpy.utils.quantity_data
Quantity data module.
This module contains Quantity dataclasses used when parsing Sensor data.
1"""Quantity data module. 2 3This module contains Quantity dataclasses used when parsing Sensor data. 4""" 5 6from dataclasses import dataclass 7from typing import Union 8from iqrfpy.exceptions import UnknownSensorTypeError 9from iqrfpy.utils.sensor_constants import SensorTypes, SensorFrcCommands 10 11__all__ = [ 12 'Temperature', 13 'CO2', 14 'VOC', 15 'ExtraLowVoltage', 16 'EarthsMagneticField', 17 'LowVoltage', 18 'Current', 19 'Power', 20 'MainsFrequency', 21 'TimeSpan', 22 'Illuminance', 23 'NO2', 24 'SO2', 25 'CO', 26 'O3', 27 'AtmosphericPressure', 28 'ColorTemperature', 29 'ParticulatesPM2_5', 30 'SoundPressureLevel', 31 'Altitude', 32 'Acceleration', 33 'NH3', 34 'Methane', 35 'ShortLength', 36 'ParticulatesPM1', 37 'ParticulatesPM4', 38 'ParticulatesPM10', 39 'TVOC', 40 'NOX', 41 'ActivityConcentration', 42 'RelativeHumidity', 43 'BinaryData7', 44 'PowerFactor', 45 'UVIndex', 46 'PH', 47 'RSSI', 48 'Action', 49 'BinaryData30', 50 'Consumption', 51 'Datetime', 52 'TimeSpanLong', 53 'Latitude', 54 'Longitude', 55 'TemperatureFloat', 56 'Length', 57 'FourBytes' 58 'DataBlock', 59 'get_sensor_class' 60] 61 62 63@dataclass 64class Temperature: 65 """Temperature dataclass.""" 66 67 type = SensorTypes.TEMPERATURE 68 name = 'Temperature' 69 short_name = 'T' 70 unit = '˚C' 71 decimal_places = 4 72 frc_commands = [ 73 SensorFrcCommands.FRC_1BYTE, 74 SensorFrcCommands.FRC_2BYTES 75 ] 76 77 78@dataclass 79class CO2: 80 """Carbon dioxide dataclass.""" 81 82 type = SensorTypes.CO2 83 name = 'Carbon dioxide' 84 short_name = 'CO2' 85 unit = 'ppm' 86 decimal_places = 0 87 frc_commands = [ 88 SensorFrcCommands.FRC_1BYTE, 89 SensorFrcCommands.FRC_2BYTES 90 ] 91 92 93@dataclass 94class VOC: 95 """Volatile organic compound dataclass.""" 96 97 type = SensorTypes.VOC 98 name = 'Volatile organic compound' 99 short_name = 'VOC' 100 unit = 'ppm' 101 decimal_places = 0 102 frc_commands = [ 103 SensorFrcCommands.FRC_1BYTE, 104 SensorFrcCommands.FRC_2BYTES 105 ] 106 107 108@dataclass 109class ExtraLowVoltage: 110 """Extra-low voltage dataclass.""" 111 112 type = SensorTypes.EXTRA_LOW_VOLTAGE 113 name = 'Extra-low voltage' 114 short_name = 'U' 115 unit = 'V' 116 decimal_places = 3 117 frc_commands = [ 118 SensorFrcCommands.FRC_2BYTES 119 ] 120 121 122@dataclass 123class EarthsMagneticField: 124 """Earth's magnetic field dataclass.""" 125 126 type = SensorTypes.EARTHS_MAGNETIC_FIELD 127 name = "Earth's magnetic field" 128 short_name = 'B' 129 unit = 'T' 130 decimal_places = 7 131 frc_commands = [ 132 SensorFrcCommands.FRC_2BYTES 133 ] 134 135 136@dataclass 137class LowVoltage: 138 """Low voltage dataclass.""" 139 140 type = SensorTypes.LOW_VOLTAGE 141 name = 'Low voltage' 142 short_name = 'U' 143 unit = 'V' 144 decimal_places = 4 145 frc_commands = [ 146 SensorFrcCommands.FRC_2BYTES 147 ] 148 149 150@dataclass 151class Current: 152 """Current dataclass.""" 153 154 type = SensorTypes.CURRENT 155 name = 'Current' 156 short_name = 'I' 157 unit = 'A' 158 decimal_places = 3 159 frc_commands = [ 160 SensorFrcCommands.FRC_2BYTES 161 ] 162 163 164@dataclass 165class Power: 166 """Power dataclass.""" 167 168 type = SensorTypes.POWER 169 name = 'Power' 170 short_name = 'P' 171 unit = 'W' 172 decimal_places = 2 173 frc_commands = [ 174 SensorFrcCommands.FRC_2BYTES 175 ] 176 177 178@dataclass 179class MainsFrequency: 180 """Mains frequency dataclass.""" 181 182 type = SensorTypes.MAINS_FREQUENCY 183 name = 'Mains frequency' 184 short_name = 'f' 185 unit = 'Hz' 186 decimal_places = 3 187 frc_commands = [ 188 SensorFrcCommands.FRC_2BYTES 189 ] 190 191 192@dataclass 193class TimeSpan: 194 """Timespan dataclass.""" 195 196 type = SensorTypes.TIMESPAN 197 name = 'Timespan' 198 short_name = 't' 199 unit = 's' 200 decimal_places = 0 201 frc_commands = [ 202 SensorFrcCommands.FRC_2BYTES 203 ] 204 205 206@dataclass 207class Illuminance: 208 """Illuminance dataclass.""" 209 210 type = SensorTypes.ILLUMINANCE 211 name = 'Illuminance' 212 short_name = 'Ev' 213 unit = 'lx' 214 decimal_places = 0 215 frc_commands = [ 216 SensorFrcCommands.FRC_2BYTES 217 ] 218 219 220@dataclass 221class NO2: 222 """Nitrogen dioxide dataclass.""" 223 224 type = SensorTypes.NO2 225 name = 'Nitrogen dioxide' 226 short_name = 'NO2' 227 unit = 'ppm' 228 decimal_places = 3 229 frc_commands = [ 230 SensorFrcCommands.FRC_2BYTES 231 ] 232 233 234@dataclass 235class SO2: 236 """Sulfur dioxide dataclass.""" 237 238 type = SensorTypes.SO2 239 name = 'Sulfur dioxide' 240 short_name = 'SO2' 241 unit = 'ppm' 242 decimal_places = 3 243 frc_commands = [ 244 SensorFrcCommands.FRC_2BYTES 245 ] 246 247 248@dataclass 249class CO: 250 """Carbon monoxide dataclass.""" 251 252 type = SensorTypes.CO 253 name = 'Carbon monoxide' 254 short_name = 'CO' 255 unit = 'ppm' 256 decimal_places = 2 257 frc_commands = [ 258 SensorFrcCommands.FRC_2BYTES 259 ] 260 261 262@dataclass 263class O3: 264 """Ozone dataclass.""" 265 266 type = SensorTypes.O3 267 name = 'Ozone' 268 short_name = 'O3' 269 unit = 'ppm' 270 decimal_places = 4 271 frc_commands = [ 272 SensorFrcCommands.FRC_2BYTES 273 ] 274 275 276@dataclass 277class AtmosphericPressure: 278 """Atmospheric pressure dataclass.""" 279 280 type = SensorTypes.ATMOSPHERIC_PRESSURE 281 name = 'Atmospheric pressure' 282 short_name = 'p' 283 unit = 'hPa' 284 decimal_places = 4 285 frc_commands = [ 286 SensorFrcCommands.FRC_2BYTES 287 ] 288 289 290@dataclass 291class ColorTemperature: 292 """Color temperature dataclass.""" 293 294 type = SensorTypes.COLOR_TEMPERATURE 295 name = 'Color temperature' 296 short_name = 'Tc' 297 unit = 'K' 298 decimal_places = 0 299 frc_commands = [ 300 SensorFrcCommands.FRC_2BYTES 301 ] 302 303 304@dataclass 305class ParticulatesPM2_5: 306 """Particulates PM2.5 dataclass.""" 307 308 type = SensorTypes.PARTICULATES_PM2_5 309 name = 'Particulates PM2.5' 310 short_name = 'PM2.5' 311 unit = 'µg/m3' 312 decimal_places = 2 313 frc_commands = [ 314 SensorFrcCommands.FRC_2BYTES 315 ] 316 317 318@dataclass 319class SoundPressureLevel: 320 """Sound pressure level dataclass.""" 321 322 type = SensorTypes.SOUND_PRESSURE_LEVEL 323 name = 'Sound pressure level' 324 short_name = 'Lp' 325 unit = 'dB' 326 decimal_places = 4 327 frc_commands = [ 328 SensorFrcCommands.FRC_2BYTES 329 ] 330 331 332@dataclass 333class Altitude: 334 """Altitude dataclass.""" 335 336 type = SensorTypes.ALTITUDE 337 name = 'Altitude' 338 short_name = 'h' 339 unit = 'm' 340 decimal_places = 2 341 frc_commands = [ 342 SensorFrcCommands.FRC_2BYTES 343 ] 344 345 346@dataclass 347class Acceleration: 348 """Acceleration dataclass.""" 349 350 types = SensorTypes.ACCELERATION 351 name = 'Acceleration' 352 short_name = 'a' 353 unit = 'm/s2' 354 decimal_places = 8 355 frc_commands = [ 356 SensorFrcCommands.FRC_2BYTES 357 ] 358 359 360@dataclass 361class NH3: 362 """Ammonia dataclass.""" 363 364 types = SensorTypes.NH3 365 name = 'Ammonia' 366 short_name = 'NH3' 367 unit = 'ppm' 368 decimal_places = 1 369 frc_commands = [ 370 SensorFrcCommands.FRC_2BYTES 371 ] 372 373 374@dataclass 375class Methane: 376 """Methane dataclass.""" 377 378 type = SensorTypes.METHANE 379 name = 'Methane' 380 short_name = 'CH4' 381 unit = '%' 382 decimal_places = 3 383 frc_commands = [ 384 SensorFrcCommands.FRC_2BYTES 385 ] 386 387 388@dataclass 389class ShortLength: 390 """Short length dataclass.""" 391 392 type = SensorTypes.SHORT_LENGTH 393 name = 'Short length' 394 short_name = 'l' 395 unit = 'm' 396 decimal_places = 3 397 frc_commands = [ 398 SensorFrcCommands.FRC_2BYTES 399 ] 400 401 402@dataclass 403class ParticulatesPM1: 404 """Particulates PM1 dataclass.""" 405 406 type = SensorTypes.PARTICULATES_PM1 407 name = 'Particulates PM1' 408 short_name = 'PM1' 409 unit = 'µg/m3' 410 decimal_places = 2 411 frc_commands = [ 412 SensorFrcCommands.FRC_2BYTES 413 ] 414 415 416@dataclass 417class ParticulatesPM4: 418 """Particulates PM4 dataclass.""" 419 420 type = SensorTypes.PARTICULATES_PM4 421 name = 'Particulates PM4' 422 short_name = 'PM4' 423 unit = 'µg/m3' 424 decimal_places = 2 425 frc_commands = [ 426 SensorFrcCommands.FRC_2BYTES 427 ] 428 429 430@dataclass 431class ParticulatesPM10: 432 """Particulates PM10 dataclass.""" 433 434 type = SensorTypes.PARTICULATES_PM10 435 name = 'Particulates PM10' 436 short_name = 'PM10' 437 unit = 'µg/m3' 438 decimal_places = 2 439 frc_commands = [ 440 SensorFrcCommands.FRC_2BYTES 441 ] 442 443 444@dataclass 445class TVOC: 446 """Total volatile organic compound dataclass.""" 447 448 type = SensorTypes.TVOC 449 name = 'Total volatile organic compound' 450 short_name = 'TVOC' 451 unit = 'µg/m3' 452 decimal_places = 0 453 frc_commands = [ 454 SensorFrcCommands.FRC_2BYTES 455 ] 456 457 458@dataclass 459class NOX: 460 """Nitrogen oxides dataclass.""" 461 462 type = SensorTypes.NOX 463 name = 'Nitrogen oxides' 464 short_name = 'NOX' 465 unit = '' 466 decimal_places = 0 467 frc_commands = [ 468 SensorFrcCommands.FRC_2BYTES 469 ] 470 471 472@dataclass 473class ActivityConcentration: 474 """Activity concentration dataclass.""" 475 476 type = SensorTypes.ACTIVITY_CONCENTRATION 477 name = 'Activity concentration' 478 short_name = 'CA' 479 unit = 'Bq/m3' 480 decimal_places = 0 481 frc_commands = [ 482 SensorFrcCommands.FRC_2BYTES 483 ] 484 485 486@dataclass 487class ParticulatesPM40: 488 """Particulates PM40 dataclass.""" 489 490 type = SensorTypes.PARTICULATES_PM40 491 name = 'Particulates PM40' 492 short_name = 'PM40' 493 unit = 'µg/m3' 494 decimal_places = 2 495 frc_commands = [ 496 SensorFrcCommands.FRC_2BYTES 497 ] 498 499 500@dataclass 501class RelativeHumidity: 502 """Relative humidity dataclass.""" 503 504 type = SensorTypes.RELATIVE_HUMIDITY 505 name = 'Relative humidity' 506 short_name = 'RH' 507 unit = '%' 508 decimal_places = 1 509 frc_commands = [ 510 SensorFrcCommands.FRC_1BYTE 511 ] 512 513 514@dataclass 515class BinaryData7: 516 """Binary data 7 dataclass.""" 517 518 type = SensorTypes.BINARYDATA7 519 name = 'Binary data7' 520 short_name = 'bin7' 521 unit = '' 522 decimal_places = 0 523 frc_commands = [ 524 SensorFrcCommands.FRC_2BITS, 525 SensorFrcCommands.FRC_1BYTE 526 ] 527 528 529@dataclass 530class PowerFactor: 531 """Power factor dataclass.""" 532 533 type = SensorTypes.POWER_FACTOR 534 name = 'Power factor' 535 short_name = 'cos θ' 536 unit = '' 537 decimal_places = 3 538 frc_commands = [ 539 SensorFrcCommands.FRC_1BYTE 540 ] 541 542 543@dataclass 544class UVIndex: 545 """UV index dataclass.""" 546 547 type = SensorTypes.UV_INDEX 548 name = 'UV index' 549 short_name = 'UV' 550 unit = '' 551 decimal_places = 3 552 frc_commands = [ 553 SensorFrcCommands.FRC_1BYTE 554 ] 555 556 557@dataclass 558class PH: 559 """PH dataclass.""" 560 561 type = SensorTypes.PH 562 name = 'pH' 563 short_name = 'pH' 564 unit = '' 565 decimal_places = 4 566 frc_commands = [ 567 SensorFrcCommands.FRC_1BYTE 568 ] 569 570 571@dataclass 572class RSSI: 573 """RSSI dataclass.""" 574 575 type = SensorTypes.RSSI 576 name = 'RSSI' 577 short_name = 'RSSI' 578 unit = 'dBm' 579 decimal_places = 1 580 frc_commands = [ 581 SensorFrcCommands.FRC_1BYTE 582 ] 583 584 585@dataclass 586class Action: 587 """Action dataclass.""" 588 589 type = SensorTypes.ACTION 590 name = 'Action' 591 short_name = 'Action' 592 unit = '' 593 decimal_places = 0 594 frc_commands = [ 595 SensorFrcCommands.FRC_1BYTE 596 ] 597 598 599@dataclass 600class BinaryData30: 601 """Binary data 30 dataclass.""" 602 603 type = SensorTypes.BINARYDATA30 604 name = 'Binary data30' 605 short_name = 'bin30' 606 unit = '' 607 decimal_places = 0 608 frc_commands = [ 609 SensorFrcCommands.FRC_2BYTES, 610 SensorFrcCommands.FRC_4BYTES 611 ] 612 613 614@dataclass 615class Consumption: 616 """Consumption dataclass.""" 617 618 type = SensorTypes.CONSUMPTION 619 name = 'Consumption' 620 short_name = 'E' 621 unit = 'Wh' 622 decimal_places = 0 623 frc_commands = [ 624 SensorFrcCommands.FRC_4BYTES 625 ] 626 627 628@dataclass 629class Datetime: 630 """Datetime dataclass.""" 631 632 type = SensorTypes.DATETIME 633 name = 'DateTime' 634 short_name = 'DateTime' 635 unit = '' 636 decimal_places = 0 637 frc_commands = [ 638 SensorFrcCommands.FRC_4BYTES 639 ] 640 641 642@dataclass 643class TimeSpanLong: 644 """Timespan long dataclass.""" 645 646 type = SensorTypes.TIMESPAN_LONG 647 name = 'Timespan long' 648 short_name = 't' 649 unit = 's' 650 decimal_places = 4 651 frc_commands = [ 652 SensorFrcCommands.FRC_4BYTES 653 ] 654 655 656@dataclass 657class Latitude: 658 """Latitude dataclass.""" 659 660 type = SensorTypes.LATITUDE 661 name = 'Latitude' 662 short_name = 'LAT' 663 unit = '°' 664 decimal_places = 7 665 frc_commands = [ 666 SensorFrcCommands.FRC_4BYTES 667 ] 668 669 670@dataclass 671class Longitude: 672 """Longitude dataclass.""" 673 674 type = SensorTypes.LONGITUDE 675 name = 'Longitude' 676 short_name = 'LONG' 677 unit = '°' 678 decimal_places = 7 679 frc_commands = [ 680 SensorFrcCommands.FRC_4BYTES 681 ] 682 683 684@dataclass 685class TemperatureFloat: 686 """Temperature float dataclass.""" 687 688 type = SensorTypes.TEMPERATURE_FLOAT 689 name = 'Temperature' 690 short_name = 'T' 691 unit = '˚C' 692 decimal_places = 7 693 frc_commands = [ 694 SensorFrcCommands.FRC_4BYTES 695 ] 696 697 698@dataclass 699class Length: 700 """Length dataclass.""" 701 702 type = SensorTypes.LENGTH 703 name = 'Length' 704 short_name = 'l' 705 unit = 'm' 706 decimal_places = 7 707 frc_commands = [ 708 SensorFrcCommands.FRC_4BYTES 709 ] 710 711 712@dataclass 713class FourBytes: 714 """Four bytes dataclass.""" 715 716 type = SensorTypes.FOUR_BYTES 717 name = 'Four bytes' 718 short_name = '4B' 719 unit = '' 720 decimal_places = 0 721 frc_commands = [ 722 SensorFrcCommands.FRC_4BYTES 723 ] 724 725 726@dataclass 727class DataBlock: 728 """Data block dataclass.""" 729 730 type = SensorTypes.DATA_BLOCK 731 name = 'Data block' 732 short_name = 'datablock' 733 unit = '' 734 decimal_places = 0 735 frc_commands = [] 736 737 738_type_classes = { 739 SensorTypes.TEMPERATURE: Temperature, 740 SensorTypes.CO2: CO2, 741 SensorTypes.VOC: VOC, 742 SensorTypes.EXTRA_LOW_VOLTAGE: ExtraLowVoltage, 743 SensorTypes.EARTHS_MAGNETIC_FIELD: EarthsMagneticField, 744 SensorTypes.LOW_VOLTAGE: LowVoltage, 745 SensorTypes.CURRENT: Current, 746 SensorTypes.POWER: Power, 747 SensorTypes.MAINS_FREQUENCY: MainsFrequency, 748 SensorTypes.TIMESPAN: TimeSpan, 749 SensorTypes.ILLUMINANCE: Illuminance, 750 SensorTypes.NO2: NO2, 751 SensorTypes.SO2: SO2, 752 SensorTypes.CO: CO, 753 SensorTypes.O3: O3, 754 SensorTypes.ATMOSPHERIC_PRESSURE: AtmosphericPressure, 755 SensorTypes.COLOR_TEMPERATURE: ColorTemperature, 756 SensorTypes.PARTICULATES_PM2_5: ParticulatesPM2_5, 757 SensorTypes.SOUND_PRESSURE_LEVEL: SoundPressureLevel, 758 SensorTypes.ALTITUDE: Altitude, 759 SensorTypes.ACCELERATION: Acceleration, 760 SensorTypes.NH3: NH3, 761 SensorTypes.METHANE: Methane, 762 SensorTypes.SHORT_LENGTH: ShortLength, 763 SensorTypes.PARTICULATES_PM1: ParticulatesPM1, 764 SensorTypes.PARTICULATES_PM4: ParticulatesPM4, 765 SensorTypes.PARTICULATES_PM10: ParticulatesPM10, 766 SensorTypes.TVOC: TVOC, 767 SensorTypes.NOX: NOX, 768 SensorTypes.ACTIVITY_CONCENTRATION: ActivityConcentration, 769 SensorTypes.PARTICULATES_PM40: ParticulatesPM40, 770 SensorTypes.RELATIVE_HUMIDITY: RelativeHumidity, 771 SensorTypes.BINARYDATA7: BinaryData7, 772 SensorTypes.POWER_FACTOR: PowerFactor, 773 SensorTypes.UV_INDEX: UVIndex, 774 SensorTypes.PH: PH, 775 SensorTypes.RSSI: RSSI, 776 SensorTypes.ACTION: Action, 777 SensorTypes.BINARYDATA30: BinaryData30, 778 SensorTypes.CONSUMPTION: Consumption, 779 SensorTypes.DATETIME: Datetime, 780 SensorTypes.TIMESPAN_LONG: TimeSpanLong, 781 SensorTypes.LATITUDE: Latitude, 782 SensorTypes.LONGITUDE: Longitude, 783 SensorTypes.TEMPERATURE_FLOAT: TemperatureFloat, 784 SensorTypes.LENGTH: Length, 785 SensorTypes.FOUR_BYTES: FourBytes, 786 SensorTypes.DATA_BLOCK: DataBlock, 787} 788 789 790def get_sensor_class(sensor_type: Union[SensorTypes, int]): 791 """Return quantity class corresponding to sensor type. 792 793 Args: 794 sensor_type (Union[SensorTypes, int]): Sensor type (represents a quantity) 795 796 Returns: 797 Quantity dataclass 798 Raises: 799 UnknownSensorTypeError: Raised if sensor type is passed as integer and the value is not recognized 800 ValueError: Raised if sensor type is recognized, but corresponding quantity data is missing 801 """ 802 if sensor_type not in SensorTypes: 803 raise UnknownSensorTypeError(f'Unknown or unsupported sensor type: {sensor_type}') 804 if sensor_type not in _type_classes: 805 raise ValueError(f'Quantity data not available for sensor type: {sensor_type}') 806 return _type_classes[sensor_type]
64@dataclass 65class Temperature: 66 """Temperature dataclass.""" 67 68 type = SensorTypes.TEMPERATURE 69 name = 'Temperature' 70 short_name = 'T' 71 unit = '˚C' 72 decimal_places = 4 73 frc_commands = [ 74 SensorFrcCommands.FRC_1BYTE, 75 SensorFrcCommands.FRC_2BYTES 76 ]
Temperature dataclass.
79@dataclass 80class CO2: 81 """Carbon dioxide dataclass.""" 82 83 type = SensorTypes.CO2 84 name = 'Carbon dioxide' 85 short_name = 'CO2' 86 unit = 'ppm' 87 decimal_places = 0 88 frc_commands = [ 89 SensorFrcCommands.FRC_1BYTE, 90 SensorFrcCommands.FRC_2BYTES 91 ]
Carbon dioxide dataclass.
94@dataclass 95class VOC: 96 """Volatile organic compound dataclass.""" 97 98 type = SensorTypes.VOC 99 name = 'Volatile organic compound' 100 short_name = 'VOC' 101 unit = 'ppm' 102 decimal_places = 0 103 frc_commands = [ 104 SensorFrcCommands.FRC_1BYTE, 105 SensorFrcCommands.FRC_2BYTES 106 ]
Volatile organic compound dataclass.
109@dataclass 110class ExtraLowVoltage: 111 """Extra-low voltage dataclass.""" 112 113 type = SensorTypes.EXTRA_LOW_VOLTAGE 114 name = 'Extra-low voltage' 115 short_name = 'U' 116 unit = 'V' 117 decimal_places = 3 118 frc_commands = [ 119 SensorFrcCommands.FRC_2BYTES 120 ]
Extra-low voltage dataclass.
123@dataclass 124class EarthsMagneticField: 125 """Earth's magnetic field dataclass.""" 126 127 type = SensorTypes.EARTHS_MAGNETIC_FIELD 128 name = "Earth's magnetic field" 129 short_name = 'B' 130 unit = 'T' 131 decimal_places = 7 132 frc_commands = [ 133 SensorFrcCommands.FRC_2BYTES 134 ]
Earth's magnetic field dataclass.
137@dataclass 138class LowVoltage: 139 """Low voltage dataclass.""" 140 141 type = SensorTypes.LOW_VOLTAGE 142 name = 'Low voltage' 143 short_name = 'U' 144 unit = 'V' 145 decimal_places = 4 146 frc_commands = [ 147 SensorFrcCommands.FRC_2BYTES 148 ]
Low voltage dataclass.
151@dataclass 152class Current: 153 """Current dataclass.""" 154 155 type = SensorTypes.CURRENT 156 name = 'Current' 157 short_name = 'I' 158 unit = 'A' 159 decimal_places = 3 160 frc_commands = [ 161 SensorFrcCommands.FRC_2BYTES 162 ]
Current dataclass.
165@dataclass 166class Power: 167 """Power dataclass.""" 168 169 type = SensorTypes.POWER 170 name = 'Power' 171 short_name = 'P' 172 unit = 'W' 173 decimal_places = 2 174 frc_commands = [ 175 SensorFrcCommands.FRC_2BYTES 176 ]
Power dataclass.
179@dataclass 180class MainsFrequency: 181 """Mains frequency dataclass.""" 182 183 type = SensorTypes.MAINS_FREQUENCY 184 name = 'Mains frequency' 185 short_name = 'f' 186 unit = 'Hz' 187 decimal_places = 3 188 frc_commands = [ 189 SensorFrcCommands.FRC_2BYTES 190 ]
Mains frequency dataclass.
193@dataclass 194class TimeSpan: 195 """Timespan dataclass.""" 196 197 type = SensorTypes.TIMESPAN 198 name = 'Timespan' 199 short_name = 't' 200 unit = 's' 201 decimal_places = 0 202 frc_commands = [ 203 SensorFrcCommands.FRC_2BYTES 204 ]
Timespan dataclass.
207@dataclass 208class Illuminance: 209 """Illuminance dataclass.""" 210 211 type = SensorTypes.ILLUMINANCE 212 name = 'Illuminance' 213 short_name = 'Ev' 214 unit = 'lx' 215 decimal_places = 0 216 frc_commands = [ 217 SensorFrcCommands.FRC_2BYTES 218 ]
Illuminance dataclass.
221@dataclass 222class NO2: 223 """Nitrogen dioxide dataclass.""" 224 225 type = SensorTypes.NO2 226 name = 'Nitrogen dioxide' 227 short_name = 'NO2' 228 unit = 'ppm' 229 decimal_places = 3 230 frc_commands = [ 231 SensorFrcCommands.FRC_2BYTES 232 ]
Nitrogen dioxide dataclass.
235@dataclass 236class SO2: 237 """Sulfur dioxide dataclass.""" 238 239 type = SensorTypes.SO2 240 name = 'Sulfur dioxide' 241 short_name = 'SO2' 242 unit = 'ppm' 243 decimal_places = 3 244 frc_commands = [ 245 SensorFrcCommands.FRC_2BYTES 246 ]
Sulfur dioxide dataclass.
249@dataclass 250class CO: 251 """Carbon monoxide dataclass.""" 252 253 type = SensorTypes.CO 254 name = 'Carbon monoxide' 255 short_name = 'CO' 256 unit = 'ppm' 257 decimal_places = 2 258 frc_commands = [ 259 SensorFrcCommands.FRC_2BYTES 260 ]
Carbon monoxide dataclass.
263@dataclass 264class O3: 265 """Ozone dataclass.""" 266 267 type = SensorTypes.O3 268 name = 'Ozone' 269 short_name = 'O3' 270 unit = 'ppm' 271 decimal_places = 4 272 frc_commands = [ 273 SensorFrcCommands.FRC_2BYTES 274 ]
Ozone dataclass.
277@dataclass 278class AtmosphericPressure: 279 """Atmospheric pressure dataclass.""" 280 281 type = SensorTypes.ATMOSPHERIC_PRESSURE 282 name = 'Atmospheric pressure' 283 short_name = 'p' 284 unit = 'hPa' 285 decimal_places = 4 286 frc_commands = [ 287 SensorFrcCommands.FRC_2BYTES 288 ]
Atmospheric pressure dataclass.
291@dataclass 292class ColorTemperature: 293 """Color temperature dataclass.""" 294 295 type = SensorTypes.COLOR_TEMPERATURE 296 name = 'Color temperature' 297 short_name = 'Tc' 298 unit = 'K' 299 decimal_places = 0 300 frc_commands = [ 301 SensorFrcCommands.FRC_2BYTES 302 ]
Color temperature dataclass.
305@dataclass 306class ParticulatesPM2_5: 307 """Particulates PM2.5 dataclass.""" 308 309 type = SensorTypes.PARTICULATES_PM2_5 310 name = 'Particulates PM2.5' 311 short_name = 'PM2.5' 312 unit = 'µg/m3' 313 decimal_places = 2 314 frc_commands = [ 315 SensorFrcCommands.FRC_2BYTES 316 ]
Particulates PM2.5 dataclass.
319@dataclass 320class SoundPressureLevel: 321 """Sound pressure level dataclass.""" 322 323 type = SensorTypes.SOUND_PRESSURE_LEVEL 324 name = 'Sound pressure level' 325 short_name = 'Lp' 326 unit = 'dB' 327 decimal_places = 4 328 frc_commands = [ 329 SensorFrcCommands.FRC_2BYTES 330 ]
Sound pressure level dataclass.
333@dataclass 334class Altitude: 335 """Altitude dataclass.""" 336 337 type = SensorTypes.ALTITUDE 338 name = 'Altitude' 339 short_name = 'h' 340 unit = 'm' 341 decimal_places = 2 342 frc_commands = [ 343 SensorFrcCommands.FRC_2BYTES 344 ]
Altitude dataclass.
347@dataclass 348class Acceleration: 349 """Acceleration dataclass.""" 350 351 types = SensorTypes.ACCELERATION 352 name = 'Acceleration' 353 short_name = 'a' 354 unit = 'm/s2' 355 decimal_places = 8 356 frc_commands = [ 357 SensorFrcCommands.FRC_2BYTES 358 ]
Acceleration dataclass.
361@dataclass 362class NH3: 363 """Ammonia dataclass.""" 364 365 types = SensorTypes.NH3 366 name = 'Ammonia' 367 short_name = 'NH3' 368 unit = 'ppm' 369 decimal_places = 1 370 frc_commands = [ 371 SensorFrcCommands.FRC_2BYTES 372 ]
Ammonia dataclass.
375@dataclass 376class Methane: 377 """Methane dataclass.""" 378 379 type = SensorTypes.METHANE 380 name = 'Methane' 381 short_name = 'CH4' 382 unit = '%' 383 decimal_places = 3 384 frc_commands = [ 385 SensorFrcCommands.FRC_2BYTES 386 ]
Methane dataclass.
389@dataclass 390class ShortLength: 391 """Short length dataclass.""" 392 393 type = SensorTypes.SHORT_LENGTH 394 name = 'Short length' 395 short_name = 'l' 396 unit = 'm' 397 decimal_places = 3 398 frc_commands = [ 399 SensorFrcCommands.FRC_2BYTES 400 ]
Short length dataclass.
403@dataclass 404class ParticulatesPM1: 405 """Particulates PM1 dataclass.""" 406 407 type = SensorTypes.PARTICULATES_PM1 408 name = 'Particulates PM1' 409 short_name = 'PM1' 410 unit = 'µg/m3' 411 decimal_places = 2 412 frc_commands = [ 413 SensorFrcCommands.FRC_2BYTES 414 ]
Particulates PM1 dataclass.
417@dataclass 418class ParticulatesPM4: 419 """Particulates PM4 dataclass.""" 420 421 type = SensorTypes.PARTICULATES_PM4 422 name = 'Particulates PM4' 423 short_name = 'PM4' 424 unit = 'µg/m3' 425 decimal_places = 2 426 frc_commands = [ 427 SensorFrcCommands.FRC_2BYTES 428 ]
Particulates PM4 dataclass.
431@dataclass 432class ParticulatesPM10: 433 """Particulates PM10 dataclass.""" 434 435 type = SensorTypes.PARTICULATES_PM10 436 name = 'Particulates PM10' 437 short_name = 'PM10' 438 unit = 'µg/m3' 439 decimal_places = 2 440 frc_commands = [ 441 SensorFrcCommands.FRC_2BYTES 442 ]
Particulates PM10 dataclass.
445@dataclass 446class TVOC: 447 """Total volatile organic compound dataclass.""" 448 449 type = SensorTypes.TVOC 450 name = 'Total volatile organic compound' 451 short_name = 'TVOC' 452 unit = 'µg/m3' 453 decimal_places = 0 454 frc_commands = [ 455 SensorFrcCommands.FRC_2BYTES 456 ]
Total volatile organic compound dataclass.
459@dataclass 460class NOX: 461 """Nitrogen oxides dataclass.""" 462 463 type = SensorTypes.NOX 464 name = 'Nitrogen oxides' 465 short_name = 'NOX' 466 unit = '' 467 decimal_places = 0 468 frc_commands = [ 469 SensorFrcCommands.FRC_2BYTES 470 ]
Nitrogen oxides dataclass.
473@dataclass 474class ActivityConcentration: 475 """Activity concentration dataclass.""" 476 477 type = SensorTypes.ACTIVITY_CONCENTRATION 478 name = 'Activity concentration' 479 short_name = 'CA' 480 unit = 'Bq/m3' 481 decimal_places = 0 482 frc_commands = [ 483 SensorFrcCommands.FRC_2BYTES 484 ]
Activity concentration dataclass.
501@dataclass 502class RelativeHumidity: 503 """Relative humidity dataclass.""" 504 505 type = SensorTypes.RELATIVE_HUMIDITY 506 name = 'Relative humidity' 507 short_name = 'RH' 508 unit = '%' 509 decimal_places = 1 510 frc_commands = [ 511 SensorFrcCommands.FRC_1BYTE 512 ]
Relative humidity dataclass.
515@dataclass 516class BinaryData7: 517 """Binary data 7 dataclass.""" 518 519 type = SensorTypes.BINARYDATA7 520 name = 'Binary data7' 521 short_name = 'bin7' 522 unit = '' 523 decimal_places = 0 524 frc_commands = [ 525 SensorFrcCommands.FRC_2BITS, 526 SensorFrcCommands.FRC_1BYTE 527 ]
Binary data 7 dataclass.
530@dataclass 531class PowerFactor: 532 """Power factor dataclass.""" 533 534 type = SensorTypes.POWER_FACTOR 535 name = 'Power factor' 536 short_name = 'cos θ' 537 unit = '' 538 decimal_places = 3 539 frc_commands = [ 540 SensorFrcCommands.FRC_1BYTE 541 ]
Power factor dataclass.
544@dataclass 545class UVIndex: 546 """UV index dataclass.""" 547 548 type = SensorTypes.UV_INDEX 549 name = 'UV index' 550 short_name = 'UV' 551 unit = '' 552 decimal_places = 3 553 frc_commands = [ 554 SensorFrcCommands.FRC_1BYTE 555 ]
UV index dataclass.
558@dataclass 559class PH: 560 """PH dataclass.""" 561 562 type = SensorTypes.PH 563 name = 'pH' 564 short_name = 'pH' 565 unit = '' 566 decimal_places = 4 567 frc_commands = [ 568 SensorFrcCommands.FRC_1BYTE 569 ]
PH dataclass.
572@dataclass 573class RSSI: 574 """RSSI dataclass.""" 575 576 type = SensorTypes.RSSI 577 name = 'RSSI' 578 short_name = 'RSSI' 579 unit = 'dBm' 580 decimal_places = 1 581 frc_commands = [ 582 SensorFrcCommands.FRC_1BYTE 583 ]
RSSI dataclass.
586@dataclass 587class Action: 588 """Action dataclass.""" 589 590 type = SensorTypes.ACTION 591 name = 'Action' 592 short_name = 'Action' 593 unit = '' 594 decimal_places = 0 595 frc_commands = [ 596 SensorFrcCommands.FRC_1BYTE 597 ]
Action dataclass.
600@dataclass 601class BinaryData30: 602 """Binary data 30 dataclass.""" 603 604 type = SensorTypes.BINARYDATA30 605 name = 'Binary data30' 606 short_name = 'bin30' 607 unit = '' 608 decimal_places = 0 609 frc_commands = [ 610 SensorFrcCommands.FRC_2BYTES, 611 SensorFrcCommands.FRC_4BYTES 612 ]
Binary data 30 dataclass.
615@dataclass 616class Consumption: 617 """Consumption dataclass.""" 618 619 type = SensorTypes.CONSUMPTION 620 name = 'Consumption' 621 short_name = 'E' 622 unit = 'Wh' 623 decimal_places = 0 624 frc_commands = [ 625 SensorFrcCommands.FRC_4BYTES 626 ]
Consumption dataclass.
629@dataclass 630class Datetime: 631 """Datetime dataclass.""" 632 633 type = SensorTypes.DATETIME 634 name = 'DateTime' 635 short_name = 'DateTime' 636 unit = '' 637 decimal_places = 0 638 frc_commands = [ 639 SensorFrcCommands.FRC_4BYTES 640 ]
Datetime dataclass.
643@dataclass 644class TimeSpanLong: 645 """Timespan long dataclass.""" 646 647 type = SensorTypes.TIMESPAN_LONG 648 name = 'Timespan long' 649 short_name = 't' 650 unit = 's' 651 decimal_places = 4 652 frc_commands = [ 653 SensorFrcCommands.FRC_4BYTES 654 ]
Timespan long dataclass.
657@dataclass 658class Latitude: 659 """Latitude dataclass.""" 660 661 type = SensorTypes.LATITUDE 662 name = 'Latitude' 663 short_name = 'LAT' 664 unit = '°' 665 decimal_places = 7 666 frc_commands = [ 667 SensorFrcCommands.FRC_4BYTES 668 ]
Latitude dataclass.
671@dataclass 672class Longitude: 673 """Longitude dataclass.""" 674 675 type = SensorTypes.LONGITUDE 676 name = 'Longitude' 677 short_name = 'LONG' 678 unit = '°' 679 decimal_places = 7 680 frc_commands = [ 681 SensorFrcCommands.FRC_4BYTES 682 ]
Longitude dataclass.
685@dataclass 686class TemperatureFloat: 687 """Temperature float dataclass.""" 688 689 type = SensorTypes.TEMPERATURE_FLOAT 690 name = 'Temperature' 691 short_name = 'T' 692 unit = '˚C' 693 decimal_places = 7 694 frc_commands = [ 695 SensorFrcCommands.FRC_4BYTES 696 ]
Temperature float dataclass.
699@dataclass 700class Length: 701 """Length dataclass.""" 702 703 type = SensorTypes.LENGTH 704 name = 'Length' 705 short_name = 'l' 706 unit = 'm' 707 decimal_places = 7 708 frc_commands = [ 709 SensorFrcCommands.FRC_4BYTES 710 ]
Length dataclass.
791def get_sensor_class(sensor_type: Union[SensorTypes, int]): 792 """Return quantity class corresponding to sensor type. 793 794 Args: 795 sensor_type (Union[SensorTypes, int]): Sensor type (represents a quantity) 796 797 Returns: 798 Quantity dataclass 799 Raises: 800 UnknownSensorTypeError: Raised if sensor type is passed as integer and the value is not recognized 801 ValueError: Raised if sensor type is recognized, but corresponding quantity data is missing 802 """ 803 if sensor_type not in SensorTypes: 804 raise UnknownSensorTypeError(f'Unknown or unsupported sensor type: {sensor_type}') 805 if sensor_type not in _type_classes: 806 raise ValueError(f'Quantity data not available for sensor type: {sensor_type}') 807 return _type_classes[sensor_type]
Return quantity class corresponding to sensor type.
Arguments:
- sensor_type (Union[SensorTypes, int]): Sensor type (represents a quantity)
Returns:
Quantity dataclass
Raises:
- UnknownSensorTypeError: Raised if sensor type is passed as integer and the value is not recognized
- ValueError: Raised if sensor type is recognized, but corresponding quantity data is missing