Skip to content

Commit

Permalink
More changes for v0.0.3 (#4)
Browse files Browse the repository at this point in the history
enrich types and vif codes

---------

Co-authored-by: stankudrow <stankudrow@reply.no>
  • Loading branch information
stankudrow and stankudrow authored Nov 28, 2024
1 parent 8173100 commit 9a86191
Show file tree
Hide file tree
Showing 7 changed files with 448 additions and 195 deletions.
4 changes: 4 additions & 0 deletions pymbus/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
class MBusError(Exception):
"""Meter-Bus Base Error."""


class MBusLengthError(MBusError):
"""Invalid length/size error."""
81 changes: 69 additions & 12 deletions pymbus/telegrams/codes/value_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,30 @@ def __init__(self, vif: VIF):
self._range = 10**pwr


class VolumeMassKilogramVIFCode(ValueInformationFieldCode):
CMASK = 0b0001_1000
class VolumeMeterCubeVIFCode(ValueInformationFieldCode):
CMASK = 0b0001_0000
EMASK = 0b0000_0111
DESC = "mass"
UNIT = "kg"
DESC = "volume"
UNIT = "m^3"

def __init__(self, vif: VIF):
super().__init__(vif)

pwr = self._vif.byte & self.EMASK
self._range = 10 ** (pwr - 3)
self._range = 10 ** (pwr - 6)


class VolumeMeterCubeVIFCode(ValueInformationFieldCode):
CMASK = 0b0001_0000
class MassKilogramVIFCode(ValueInformationFieldCode):
CMASK = 0b0001_1000
EMASK = 0b0000_0111
DESC = "volume"
UNIT = "m^3"
DESC = "mass"
UNIT = "kg"

def __init__(self, vif: VIF):
super().__init__(vif)

pwr = self._vif.byte & self.EMASK
self._range = 10 ** (pwr - 6)
self._range = 10 ** (pwr - 3)


class OnTimeVIFCode(ValueInformationFieldCode):
Expand All @@ -102,7 +102,7 @@ def __init__(self, vif: VIF):
self.UNIT = "hour"
if unit == 1:
self.UNIT = "minute"
else:
if unit == 0:
self.UNIT = "second"


Expand All @@ -123,13 +123,70 @@ def __init__(self, vif: VIF):
self._range = 10 ** (pwr - 3)


class PowerJoulePerHourVIFCode(ValueInformationFieldCode):
CMASK = 0b0011_0000
EMASK = 0b0000_0111
DESC = "power"
UNIT = "J/h"

def __init__(self, vif: VIF):
super().__init__(vif)

pwr = self._vif.byte & self.EMASK
self._range = 10 ** (pwr)


class VolumeFlowCubicMeterPerHourVIFCode(ValueInformationFieldCode):
CMASK = 0b0011_1000
EMASK = 0b0000_0111
DESC = "volume flow"
UNIT = "m^3/h"

def __init__(self, vif: VIF):
super().__init__(vif)

pwr = self._vif.byte & self.EMASK
self._range = 10 ** (pwr - 6)


class VolumeFlowCubicMeterPerMinuteVIFCode(ValueInformationFieldCode):
CMASK = 0b0100_0000
EMASK = 0b0000_0111
DESC = "volume flow"
UNIT = "m^3/min"

def __init__(self, vif: VIF):
super().__init__(vif)

pwr = self._vif.byte & self.EMASK
self._range = 10 ** (pwr - 7)


class VolumeFlowCubicMeterPerSecondVIFCode(ValueInformationFieldCode):
CMASK = 0b0100_1000
EMASK = 0b0000_0111
DESC = "volume flow"
UNIT = "m^3/s"

def __init__(self, vif: VIF):
super().__init__(vif)

pwr = self._vif.byte & self.EMASK
self._range = 10 ** (pwr - 9)


VIF_CODE_TYPES: list[ValueInformationFieldCode] = {
EnergyWattHourVIFCode,
EnergyJouleVIFCode,
VolumeMeterCubeVIFCode,
VolumeMassKilogramVIFCode,
MassKilogramVIFCode,
OnTimeVIFCode,
OperatingTimeVIFCode,
PowerWattVIFCode,
PowerJoulePerHourVIFCode,
VolumeFlowCubicMeterPerHourVIFCode,
VolumeFlowCubicMeterPerMinuteVIFCode,
VolumeFlowCubicMeterPerSecondVIFCode,
}


Expand Down
Loading

0 comments on commit 9a86191

Please sign in to comment.