Skip to content

Commit

Permalink
Property value in the EPC_SUPER_FUNCTIONS constant
Browse files Browse the repository at this point in the history
rel. #67, EPC_SUPER_FUNCTION too process
  • Loading branch information
nao-pon committed Feb 23, 2024
1 parent 44f6ce9 commit 5a9e931
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
46 changes: 28 additions & 18 deletions pychonet/EchonetInstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
from pychonet.lib.epc import EPC_CODE, EPC_SUPER
from pychonet.lib.epc_functions import EPC_SUPER_FUNCTIONS


def call_epc_function(epc_function, edt):
if type(epc_function) == list:
if list(epc_function) == 3:
data = epc_function[0](
edt,
epc_function[1],
epc_function[2],
)
else:
data = epc_function[0](edt, epc_function[1])
else:
data = epc_function(edt)
return data


"""
Superclass for Echonet instance objects.
"""
Expand Down Expand Up @@ -145,10 +161,11 @@ async def update(self, attributes=None, no_request=False):
): # check if function is defined in the superset
returned_json_data.update(
{
epc: EPC_SUPER_FUNCTIONS[epc](
epc: call_epc_function(
EPC_SUPER_FUNCTIONS[epc],
self._api._state[self._host]["instances"][self._eojgc][
self._eojcc
][self._eojci][epc]
][self._eojci][epc],
)
}
)
Expand All @@ -167,23 +184,16 @@ async def update(self, attributes=None, no_request=False):
elif epc in list(
self.EPC_FUNCTIONS.keys()
): # check the class-specific EPC function table.
raw_data = self._api._state[self._host]["instances"][self._eojgc][
self._eojcc
][self._eojci][epc]
if type(self.EPC_FUNCTIONS[epc]) == list:
if list(self.EPC_FUNCTIONS[epc]) == 3:
data = self.EPC_FUNCTIONS[epc][0](
raw_data,
self.EPC_FUNCTIONS[epc][1],
self.EPC_FUNCTIONS[epc][2],
)
else:
data = self.EPC_FUNCTIONS[epc][0](
raw_data, self.EPC_FUNCTIONS[epc][1]
returned_json_data.update(
{
epc: call_epc_function(
self.EPC_FUNCTIONS[epc],
self._api._state[self._host]["instances"][self._eojgc][
self._eojcc
][self._eojci][epc],
)
else:
data = self.EPC_FUNCTIONS[epc](raw_data)
returned_json_data.update({epc: data})
}
)
# returned_json_data.update(
# {
# epc: self.EPC_FUNCTIONS[epc](
Expand Down
2 changes: 1 addition & 1 deletion pychonet/lib/epc_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _009A(edt): # cumulative runtime


EPC_SUPER_FUNCTIONS = {
0x80: _0080,
0x80: [_int, DICT_30_ON_OFF],
0x83: _0083,
0x84: _int,
0x85: _int,
Expand Down

0 comments on commit 5a9e931

Please sign in to comment.