Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions pychonet/DistributedGeneratorElectricEnergyMeter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# pychonet/DistributedGeneratorElectricEnergyMeter.py
from pychonet.EchonetInstance import EchonetInstance
from pychonet.lib.epc_functions import (
_int,
_signed_int,
_to_string,
_yyyy_mm_dd,
_hh_mm,
)

#ENL_DGEEM_COEF = 0xD3
#ENL_DGEEM_DIGITS = 0xD7
ENL_DGEEM_ENG_UNIT = 0xD4
ENL_DGEEM_ENG_ACI = 0xE0
ENL_DGEEM_ENG_ACO = 0xE2
ENL_DGEEM_ENG_INO = 0xE4
ENL_DGEEM_INSTANT_AIO = 0xE9
ENL_DGEEM_INSTANT_INO = 0xEA


class DistributedGeneratorElectricEnergyMeter(EchonetInstance):
"""
ECHONET Lite: 0x02-0x8E
Distributed generator electric energy meter(分布型発電電力量計)
02,8E,01,分散型電源電力量メータ,72,D4,Unit for cumulative amount of electric energy,?,unsignedChar
02,8E,01,分散型電源電力量メータ,72,E0,Measured cumulative amount of electric energy (AC input),W,unsignedLong
02,8E,01,分散型電源電力量メータ,72,E2,Measured cumulative amount of electric energy (AC output),W,unsignedLong
02,8E,01,分散型電源電力量メータ,72,E4,Measured cumulative amount of electric energy (independent output),W,unsignedLong
02,8E,01,分散型電源電力量メータ,72,E9,Measured instantaneous electric power (AC input/output),W,signedLong
02,8E,01,分散型電源電力量メータ,72,EA,Measured instantaneous electric power (independent output),W,signedLong
"""

EPC_FUNCTIONS = {
# 通用
0x80: _int, # Operation status
#0x83: _to_string, # Identification number???
#0x97: _hh_mm, # Current time setting???
0x98: _yyyy_mm_dd, # Current date setting

# 单位
0xD4: [
_int,
{
0x00: 1,
0x01: 0.1,
0x02: 0.01,
0x03: 0.001,
0x04: 0.0001,
0x0A: 10,
0x0B: 100,
0x0C: 1000,
0x0D: 10000,
},
None,
], # 積算電力量単位 (unsignedChar) x kWh —— 上层解释倍率

# 累计量(unsigned long)
0xE0: _int, # 積算電力量計測値(交流入力)
0xE2: _int, # 積算電力量計測値(交流出力)
0xE4: _int, # 積算電力量計測値(自立出力)

# 瞬时功率/电力(signed long)
0xE9: _signed_int, # 交流入出力計測値
0xEA: _signed_int, # 自立出力計測値
}

def __init__(self, host, api_connector=None, instance=0x01):
self._eojgc = 0x02
self._eojcc = 0x8E
EchonetInstance.__init__(
self, host, self._eojgc, self._eojcc, instance, api_connector
)

async def getUnit(self):
return await self.getMessage(ENL_DGEEM_ENG_UNIT)
3 changes: 2 additions & 1 deletion pychonet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from .StorageBattery import StorageBattery
from .TemperatureSensor import TemperatureSensor
from .WaterFlowMeter import WaterFlowMeter

from .DistributedGeneratorElectricEnergyMeter import DistributedGeneratorElectricEnergyMeter

def Factory(host, server, eojgc, eojcc, eojci=0x01):
instance = None
Expand Down Expand Up @@ -69,6 +69,7 @@ def Factory(host, server, eojgc, eojcc, eojci=0x01):
f"{0x02}-{0x82}": GasMeter,
f"{0x02}-{0x87}": DistributionPanelMeter,
f"{0x02}-{0x88}": LowVoltageSmartElectricEnergyMeter,
f"{0x02}-{0x8E}": DistributedGeneratorElectricEnergyMeter,
f"{0x02}-{0x90}": GeneralLighting,
f"{0x02}-{0x91}": SingleFunctionLighting,
f"{0x02}-{0xA3}": LightingSystem,
Expand Down
27 changes: 26 additions & 1 deletion pychonet/echonetapiclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,32 @@ async def echonetMessageReceived(self, raw_data, addr):
else: # process each EPC in order
if epc == ENL_SETMAP or epc == ENL_GETMAP or epc == ENL_STATMAP:
map = EPC_SUPER_FUNCTIONS[epc](opc["EDT"])
self._state[host]["instances"][seojgc][seojcc][seojci][epc] = map
#self._state[host]["instances"][seojgc][seojcc][seojci][epc] = map
#comment out origin line above
#use int to avoid using bytes/str
try:
seojgc_i = int(seojgc)
seojcc_i = int(seojcc)
seojci_i = int(seojci)
epc_i = int(epc)
except Exception:
#bytes in some versions?;here we use int
def _to_int(x):
if isinstance(x, (bytes, bytearray)) and len(x) == 1:
return x[0]
return int(x)
seojgc_i = _to_int(seojgc)
seojcc_i = _to_int(seojcc)
seojci_i = _to_int(seojci)
epc_i = _to_int(epc)

host_state = self._state.setdefault(host, {})
instances = host_state.setdefault("instances", {})
layer_gc = instances.setdefault(seojgc_i, {})
layer_cc = layer_gc.setdefault(seojcc_i, {})
layer_ci = layer_cc.setdefault(seojci_i, {})
layer_ci[epc_i] = map
#end of edit
elif epc in (ENL_UID, ENL_MANUFACTURER, ENL_PRODUCT_CODE):
try:
self._state[host]["instances"][seojgc][seojcc][seojci][
Expand Down
1 change: 1 addition & 0 deletions pychonet/lib/eojx.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
0x88: "Low voltage smart electric energy meter",
0x89: "Smart gas meter",
0x8A: "High voltage smart electric energy meter",
0x8E: "Distributed generator electric energy meter",
0x90: "General lighting",
0x91: "Single function lighting",
0x99: "Emergency lighting",
Expand Down
4 changes: 2 additions & 2 deletions pychonet/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version_info__ = (2, 6, 18)
__version__ = ".".join(map(str, __version_info__))
__version_info__ = (2, 6, 20, "dev2")
__version__ = "2.6.20dev2"