Skip to content

Commit 4aeef0b

Browse files
committed
Create new response message objects on demand
to prevent reuse of objects
1 parent 862d5f6 commit 4aeef0b

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

plugwise_usb/messages/responses.py

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -909,31 +909,6 @@ def __init__(self) -> None:
909909
self._params += [self.is_get, self.relay]
910910

911911

912-
ID_TO_MESSAGE = {
913-
b"0002": StickNetworkInfoResponse(),
914-
b"0003": NodeSpecificResponse(),
915-
b"0005": CirclePlusConnectResponse(),
916-
NODE_JOIN_ID: NodeJoinAvailableResponse(),
917-
b"000E": NodePingResponse(),
918-
b"0010": NodeImageValidationResponse(),
919-
b"0011": StickInitResponse(),
920-
b"0013": CirclePowerUsageResponse(),
921-
b"0015": CircleLogDataResponse(),
922-
b"0019": CirclePlusScanResponse(),
923-
b"001D": NodeRemoveResponse(),
924-
b"0024": NodeInfoResponse(),
925-
b"0027": EnergyCalibrationResponse(),
926-
b"003A": CirclePlusRealTimeClockResponse(),
927-
b"003F": CircleClockResponse(),
928-
b"0049": CircleEnergyLogsResponse(),
929-
NODE_SWITCH_GROUP_ID: NodeSwitchGroupResponse(),
930-
b"0060": NodeFeaturesResponse(),
931-
b"0100": NodeAckResponse(),
932-
SENSE_REPORT_ID: SenseReportResponse(),
933-
b"0139": CircleRelayInitStateResponse(),
934-
}
935-
936-
937912
def get_message_object(
938913
identifier: bytes, length: int, seq_id: bytes
939914
) -> PlugwiseResponse | None:
@@ -956,4 +931,47 @@ def get_message_object(
956931
if length == 36:
957932
return NodeResponse()
958933
return None
959-
return ID_TO_MESSAGE.get(identifier, None)
934+
935+
# Regular response ID's
936+
if identifier == b"0002":
937+
return StickNetworkInfoResponse()
938+
if identifier == b"0003":
939+
return NodeSpecificResponse()
940+
if identifier == b"0005":
941+
return CirclePlusConnectResponse()
942+
if identifier == NODE_JOIN_ID:
943+
return NodeJoinAvailableResponse()
944+
if identifier == b"000E":
945+
return NodePingResponse()
946+
if identifier == b"0010":
947+
return NodeImageValidationResponse()
948+
if identifier == b"0011":
949+
return StickInitResponse()
950+
if identifier == b"0013":
951+
return CirclePowerUsageResponse()
952+
if identifier == b"0015":
953+
return CircleLogDataResponse()
954+
if identifier == b"0019":
955+
return CirclePlusScanResponse()
956+
if identifier == b"001D":
957+
return NodeRemoveResponse()
958+
if identifier == b"0024":
959+
return NodeInfoResponse()
960+
if identifier == b"0027":
961+
return EnergyCalibrationResponse()
962+
if identifier == b"003A":
963+
return CirclePlusRealTimeClockResponse()
964+
if identifier == b"003F":
965+
return CircleClockResponse()
966+
if identifier == b"0049":
967+
return CircleEnergyLogsResponse()
968+
if identifier == NODE_SWITCH_GROUP_ID:
969+
return NodeSwitchGroupResponse()
970+
if identifier == b"0060":
971+
return NodeFeaturesResponse()
972+
if identifier == b"0100":
973+
return NodeAckResponse()
974+
if identifier == SENSE_REPORT_ID:
975+
return SenseReportResponse()
976+
if identifier == b"0139":
977+
return CircleRelayInitStateResponse()

0 commit comments

Comments
 (0)