Skip to content

Commit

Permalink
Add enum values for RCC 512 User Level
Browse files Browse the repository at this point in the history
  • Loading branch information
ankohanse committed Dec 7, 2024
1 parent a8072f9 commit de8af86
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 11 deletions.
2 changes: 1 addition & 1 deletion example_api_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def main():

# Retrieve param #5012 from RCC (User Level)
value = await api.requestValue(param_5012, "RCC") # rcc address range is only 501, or use "RCC"
logger.info(f"RCC 5012: {value} {param_5012.unit} ({param_5012.name})")
logger.info(f"RCC 5012: {param_5012.enum_value(value)} ({param_5012.name})")

# Retrieve and Update param 1107 on the first Xtender (Maximum current of AC source)
value = await api.requestValue(param_1107, "XT1")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "aioxcom"
version = "1.6.0"
version = "1.6.1"
authors = [
{ name="Anko Hanse", email="[email protected]" },
]
Expand Down
4 changes: 0 additions & 4 deletions src/aioxcom/xcom_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,6 @@ async def updateValue(self, parameter: XcomDatapoint, value, dstAddr = 100, retr
_LOGGER.warn(f"Ignoring attempt to update readonly infos value {parameter}")
return None

if parameter.level == LEVEL.VO:
_LOGGER.warn(f"Ignoring attempt to update view-only params value {parameter}")
return None

if type(dstAddr) is str:
dstAddr = XcomDeviceFamilies.getAddrByCode(dstAddr)

Expand Down
6 changes: 3 additions & 3 deletions src/aioxcom/xcom_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ def from_str(s: str):

### data types
class LEVEL(IntEnum):
INFO = 0x0000
INFO = 0x0001
VO = 0x0000 # View Only. Used for param RCC 5012 (User Level)
BASIC = 0x0010
EXPERT = 0x0020
INST = 0x0030 # Installer
QSP = 0x0040 # Qualified Service Person
VO = 0xFFFF # View Only. Used for param 5012

@staticmethod
def from_str(s: str):
match s.upper():
case 'INFO': return LEVEL.INFO
case 'VO' | 'V.O.': return LEVEL.VO
case 'BASIC': return LEVEL.BASIC
case 'EXPERT': return LEVEL.EXPERT
case 'INST' | 'INST.': return LEVEL.INST
case 'QSP': return LEVEL.QSP
case 'VO' | 'V.O.': return LEVEL.VO
case _: raise Exception(f"Unknown level: '{s}'")

def __str__(self):
Expand Down
21 changes: 21 additions & 0 deletions src/aioxcom/xcom_datapoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ def obj_type(self):

_LOGGER.debug(f"Unknown obj_type for datapoint {self.nr} with level {self.level} and format {self.format}")
return OBJ_TYPE.INFO

def enum_value(self, key):
if self.format not in [FORMAT.LONG_ENUM, FORMAT.SHORT_ENUM]:
return None

key = str(key)
if not isinstance(self.options, dict) or key not in self.options:
return key
else:
return self.options[key]

def enum_key(self, value):
if self.format not in [FORMAT.LONG_ENUM, FORMAT.SHORT_ENUM]:
return None

if not isinstance(self.options, dict) or value not in self.options.values():
return None
else:
key = next((key for key,val in self.options.items() if val==value), None)
return int(key)



class XcomDataset:
Expand Down
2 changes: 1 addition & 1 deletion src/aioxcom/xcom_datapoints_240v.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@
{ "fam": "rcc", "lvl": "Basic", "pnr": 5036, "nr": 5039, "name": " Choice of the third language", "unit": "", "def": 4, "min": 1, "max": 128, "fmt": "LONG ENUM", "inc": "Only 1 bit", "opt": {"1":"English", "2":"French", "4":"German", "8":"Spanish", "16":"Dutch", "32":"Latinoelinka", "64":"Italian", "128":"Slovak"} },
{ "fam": "rcc", "lvl": "Basic", "pnr": 5036, "nr": 5040, "name": " Choice of the fourth language", "unit": "", "def": 8, "min": 1, "max": 128, "fmt": "LONG ENUM", "inc": "Only 1 bit", "opt": {"1":"English", "2":"French", "4":"German", "8":"Spanish", "16":"Dutch", "32":"Latinoelinka", "64":"Italian", "128":"Slovak"} },
{ "fam": "rcc", "lvl": "Basic", "pnr": 50, "nr": 5002, "name": "Date", "unit": "Seconds", "def": 0, "min": 0, "max": 0, "fmt": "INT32", "inc": 1 },
{ "fam": "rcc", "lvl": "V.O.", "pnr": 50, "nr": 5012, "name": "User level", "unit": "", "def": 16, "min": 0, "max": 111, "fmt": "INT32", "inc": "" },
{ "fam": "rcc", "lvl": "V.O.", "pnr": 50, "nr": 5012, "name": "User level", "unit": "", "def": 16, "min": 0, "max": 111, "fmt": "LONG ENUM", "inc": "", "opt": {"0":"VIEW ONLY", "16":"BASIC", "32":"EXPERT", "48":"INSTALLER", "64":"QSP"} },
{ "fam": "rcc", "lvl": "Expert", "pnr": 50, "nr": 5019, "name": "Force remote control to user BASIC level", "unit": "", "def": "S", "min": "S", "max": "S", "fmt": "INT32", "inc": "Signal" },
{ "fam": "rcc", "lvl": "Expert", "pnr": 50, "nr": 5057, "name": "DATALOGGER", "unit": "", "def": "", "min": "", "max": "", "fmt": "ONLY LEVEL", "inc": "Menu" },
{ "fam": "rcc", "lvl": "Expert", "pnr": 5057, "nr": 5101, "name": " Datalogger enabled", "unit": "", "def": 1, "min": 1, "max": 4, "fmt": "LONG ENUM", "inc": "Only 1 bit", "opt": {"1":"Automatic", "2":"Yes", "4":"No"} },
Expand Down
1 change: 1 addition & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ async def test_connect(name, start_server, start_client, wait_server, exp_server
("update param err", 1107, 100, 4.0, 100, SCOM_SERVICE.WRITE, SCOM_OBJ_TYPE.PARAMETER, 1107, SCOM_QSP_ID.UNSAVED_VALUE, 0x03, SCOM_ERROR_CODES.WRITE_PROPERTY_FAILED, None, XcomApiResponseIsError),
("update param timeout", 1107, 100, 4.0, 100, SCOM_SERVICE.WRITE, SCOM_OBJ_TYPE.PARAMETER, 1107, SCOM_QSP_ID.UNSAVED_VALUE, 0x00, b'', True, XcomApiTimeoutException),
("request param vo", 5012, 501, None, 501, SCOM_SERVICE.READ, SCOM_OBJ_TYPE.PARAMETER, 5012, SCOM_QSP_ID.UNSAVED_VALUE, 0x02, XcomData.pack(32, FORMAT.INT32), 32, None),
("update param vo", 5012, 501, 32, 501, SCOM_SERVICE.WRITE, SCOM_OBJ_TYPE.PARAMETER, 5012, SCOM_QSP_ID.UNSAVED_VALUE, 0x03, SCOM_ERROR_CODES.ACCESS_DENIED, None, XcomApiResponseIsError),
]
)
async def test_request(name, test_nr, test_dest, test_value_update, exp_dst_addr, exp_svc_id, exp_obj_type, exp_obj_id, exp_prop_id, rsp_flags, rsp_data, exp_value, exp_except, request):
Expand Down
24 changes: 23 additions & 1 deletion tests/test_datapoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ async def test_nr():
param = dataset.getByNr(5012, "rcc")
assert param.family_id == "rcc"
assert param.nr == 5012
assert param.format == FORMAT.INT32
assert param.format == FORMAT.LONG_ENUM
assert param.obj_type == OBJ_TYPE.PARAMETER
assert param.options != None
assert type(param.options) is dict

with pytest.raises(XcomDatapointUnknownException):
param = dataset.getByNr(9999)
Expand All @@ -56,6 +58,26 @@ async def test_nr():
param = dataset.getByNr(3000, "bsp")


@pytest.mark.asyncio
async def test_enum():
dataset = await XcomDataset.create(VOLTAGE.AC240)

param = dataset.getByNr(1552)
assert param.options != None
assert type(param.options) is dict
assert len(param.options) == 3

assert param.enum_value(1) == "Slow"
assert param.enum_value("1") == "Slow"
assert param.enum_value(0) == "0"
assert param.enum_value("0") == "0"

assert param.enum_key("Slow") == 1
assert param.enum_key("Unknown") == None
assert param.enum_key(1) == None
assert param.enum_key("1") == None


@pytest.mark.asyncio
async def test_menu():
dataset = await XcomDataset.create(VOLTAGE.AC240)
Expand Down

0 comments on commit de8af86

Please sign in to comment.