File: reading.md

package info (click to toggle)
python-iometer 0.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 152 kB
  • sloc: python: 591; makefile: 3
file content (81 lines) | stat: -rw-r--r-- 2,083 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Reading Documentation

The Reading module provides classes for handling IOmeter readings. 

## OBIS Codes

Important OBIS codes used in the module:

- `01-00:01.08.00*ff`: Total energy consumption on all tariffs
- `01-00:02.08.00*ff`: Total energy production on all tariffs
- `01-00:10.07.00*ff`: Current power consumption

## Classes

### Reading
Top-level class for complete meter reading, currently consist of one meter:
```python
@dataclass
class Reading:
    __typename: str = "iometer.reading.v1"
    meter: Meter = None

    # OBIS code constants
    TOTAL_CONSUMPTION_OBIS = "01-00:01.08.00*ff"
    TOTAL_PRODUCTION_OBIS = "01-00:02.08.00*ff"

    @classmethod
    def from_json(cls, json_str: str) -> 'Reading':
        # Creates Reading instance from JSON string

    def get_total_consumption(self) -> float:
        # Returns total consumption in Wh

    def get_total_production(self) -> float:
        # Returns total production in Wh

    def get_current_power(self) -> float:
        # Returns current power consumption in W
```

### Meter
Represents the meter device and its reading:
```python
@dataclass
class Meter:
    number: str            # Meter serial number
    reading: MeterReading  # Current meter reading
```

### MeterReading
Represents a collection of register readings at a specific time:
```python
@dataclass
class MeterReading:
    time: datetime          # Timestamp of the reading in UTC
    registers: List[Register] # List of register readings

    def get_register_by_obis(self, obis: str) -> Register | None:
        # Returns specific register by OBIS code
```

### Register
Represents a single meter register reading:
```python
@dataclass
class Register:
    obis: str      # OBIS code identifying the reading type
    value: float   # Reading value
    unit: str      # Unit of measurement (e.g., "Wh", "W")
```

### JSON Handling
```python
# Parse from JSON
reading = Reading.from_json(json_data)

# Access data
meter_number = reading.meter.number
timestamp = reading.meter.reading.time
consumption = reading.get_total_consumption()
```