Skip to content

Commit c0aa6b9

Browse files
atudor2jath03
andauthored
Skip unsupported plugins instead of raising KeyError (#95)
* Skip unsupported plugins instead of raising KeyError * Remove explanatory comment in create_plugin --------- Co-authored-by: Jack Hughes <jackthughes@yahoo.com>
1 parent 4c0c058 commit c0aa6b9

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎openrgb/orgb.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,10 @@ def _callback(self, device: int, type: int, data: Any):
420420
elif type == utils.PacketType.REQUEST_PLUGIN_LIST:
421421
for plugin in data:
422422
if (all(plugin.id != existing.id for existing in self.plugins)):
423-
self.plugins.append(create_plugin(plugin, self.comms))
423+
# Plugins that are not supported should be skipped
424+
new_plugin = create_plugin(plugin, self.comms)
425+
if new_plugin is not None:
426+
self.plugins.append(new_plugin)
424427
elif type == utils.PacketType.PLUGIN_SPECIFIC:
425428
next(plugin for plugin in self.plugins if plugin.id == device)._recv(data)
426429

‎openrgb/plugins/__init__.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import annotations
2+
from typing import Optional
23
from openrgb.utils import Plugin
34
from openrgb.network import NetworkClient
45
from openrgb.plugins.common import ORGBPlugin
@@ -10,5 +11,8 @@
1011
}
1112

1213

13-
def create_plugin(plugin: Plugin, comms: NetworkClient) -> ORGBPlugin:
14-
return PLUGIN_NAMES[plugin.name](plugin, comms)
14+
def create_plugin(plugin: Plugin, comms: NetworkClient) -> Optional[ORGBPlugin]:
15+
plugin_class = PLUGIN_NAMES.get(plugin.name)
16+
if plugin_class is None:
17+
return None
18+
return plugin_class(plugin, comms)

0 commit comments

Comments
 (0)