Skip to content

Commit

Permalink
Initialize unknown command classes
Browse files Browse the repository at this point in the history
This so we can interview at least the version of the class
  • Loading branch information
mickeprag committed Apr 3, 2020
1 parent 5e41b79 commit 12d867c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
33 changes: 29 additions & 4 deletions pyzwave/commandclass/CommandClass.py
Expand Up @@ -72,14 +72,14 @@ async def wrapper():
version = await commandClass.requestVersion()
if version == 0:
_LOGGER.warning(
"Unable to determine command class version for %s", commandClass.NAME,
"Unable to determine command class version for %s", commandClass.name,
)
return
try:
commandClass._interviewed = False # pylint: disable=protected-access
retval = await interview()
except asyncio.TimeoutError:
_LOGGER.warning("Timeout interviewing command class %s", commandClass.NAME)
_LOGGER.warning("Timeout interviewing command class %s", commandClass.name)
return False
if retval is not False:
commandClass._interviewed = True # pylint: disable=protected-access
Expand Down Expand Up @@ -143,6 +143,10 @@ def interviewed(self) -> bool:
"""Return is this command class has been fully interviewed or not"""
return self._interviewed

@property
def name(self):
return self.NAME

@property
def node(self):
"""Returns the node this command class belongs to"""
Expand Down Expand Up @@ -203,12 +207,33 @@ def __setstate__(self, state):
def load(cmdClass: int, securityS0: bool, node):
"""Load and create a new command class instance from the given command class id"""
# pylint: disable=invalid-name
CommandClassCls = ZWaveCommandClass.get(cmdClass, CommandClass)
instance = CommandClassCls(securityS0, node)
CommandClassCls = ZWaveCommandClass.get(cmdClass, None)
if CommandClassCls:
instance = CommandClassCls(securityS0, node)
else:
instance = UnknownCommandClass(securityS0, node, cmdClass)
# Decorate the interview function
instance.interview = interviewDecorator(instance.interview)
return instance


class UnknownCommandClass(CommandClass):
"""
Wrapper class for wrapping unknown command classes.
"""

def __init__(self, securityS0, node, id):
super().__init__(securityS0, node)
self._id = id

@property
def id(self) -> int: # pylint: disable=invalid-name
return self._id

@property
def name(self):
return "UNKNOWN (0x{:X})".format(self.id)


# pylint: disable=wrong-import-position
from . import Version
2 changes: 1 addition & 1 deletion pyzwave/node.py
Expand Up @@ -180,7 +180,7 @@ async def interview(self):
try:
await cmdClass.interview()
except asyncio.TimeoutError:
_LOGGER.warning("Timeout interviewing %s", cmdClass.NAME)
_LOGGER.warning("Timeout interviewing %s", cmdClass.name)

@property
def isFailed(self) -> bool:
Expand Down
1 change: 1 addition & 0 deletions tests/test_node.py
Expand Up @@ -167,6 +167,7 @@ async def interview():

mocknode.supported[Version.COMMAND_CLASS_VERSION].interview = interview
mocknode.supported[Basic.COMMAND_CLASS_BASIC].interview = interview
mocknode.supported[SwitchBinary.COMMAND_CLASS_SWITCH_BINARY].interview = interview
await mocknode.interview()
assert mocknode.supported[Version.COMMAND_CLASS_VERSION].version == 0

Expand Down

0 comments on commit 12d867c

Please sign in to comment.