iqrfpy.response_factory
1from abc import ABC, abstractmethod 2from typing import Optional, Union 3 4import iqrfpy.peripherals.binaryoutput.responses as bo_responses 5import iqrfpy.peripherals.coordinator.responses as c_responses 6import iqrfpy.peripherals.eeeprom.responses as eeeprom_responses 7import iqrfpy.peripherals.eeprom.responses as eeprom_responses 8import iqrfpy.peripherals.exploration.responses as exploration_responses 9import iqrfpy.peripherals.frc.responses as frc_responses 10import iqrfpy.peripherals.io.responses as io_responses 11import iqrfpy.peripherals.ledg.responses as ledg_responses 12import iqrfpy.peripherals.ledr.responses as ledr_responses 13import iqrfpy.peripherals.node.responses as node_responses 14import iqrfpy.peripherals.os.responses as os_responses 15import iqrfpy.peripherals.ram.responses as ram_responses 16import iqrfpy.peripherals.sensor.responses as sensor_responses 17import iqrfpy.peripherals.thermometer.responses as thermometer_responses 18import iqrfpy.peripherals.uart.responses as uart_responses 19from iqrfpy.async_response import AsyncResponse 20from iqrfpy.confirmation import Confirmation 21from iqrfpy.enums.commands import * 22from iqrfpy.enums.message_types import * 23from iqrfpy.enums.peripherals import * 24from iqrfpy.exceptions import UnsupportedMessageTypeError, UnsupportedPeripheralCommandError, UnsupportedPeripheralError 25from iqrfpy.iresponse import IResponse 26from iqrfpy.peripherals.generic.responses import GenericResponse 27from iqrfpy.utils.common import Common 28from iqrfpy.utils.dpa import BYTE_MAX, CONFIRMATION_PACKET_LEN, REQUEST_PCMD_MAX, RESPONSE_PCMD_MIN, ResponseCodes, \ 29 ResponsePacketMembers, PNUM_MAX 30 31__all__ = [ 32 'ResponseFactory', 33 'BaseFactory', 34] 35 36 37class BaseFactory(ABC): 38 """Response factory class abstraction.""" 39 40 @staticmethod 41 @abstractmethod 42 def create_from_dpa(dpa: bytes) -> IResponse: 43 """Returns a response object created from DPA message.""" 44 45 @staticmethod 46 @abstractmethod 47 def create_from_json(json: dict) -> IResponse: 48 """Returns a response object created from JSON API message.""" 49 50 51# Generic factories 52class GenericResponseFactory(BaseFactory): 53 54 @staticmethod 55 def create_from_dpa(dpa: bytes) -> GenericResponse: 56 return GenericResponse.from_dpa(dpa=dpa) 57 58 @staticmethod 59 def create_from_json(json: dict) -> IResponse: 60 return GenericResponse.from_json(json=json) 61 62 63class AsyncResponseFactory(BaseFactory): 64 65 @staticmethod 66 def create_from_dpa(dpa: bytes) -> IResponse: 67 return AsyncResponse.from_dpa(dpa=dpa) 68 69 @staticmethod 70 def create_from_json(json: dict) -> IResponse: 71 return AsyncResponse.from_json(json=json) 72 73 74class ConfirmationFactory(BaseFactory): 75 76 @staticmethod 77 def create_from_dpa(dpa: bytes) -> Confirmation: 78 return Confirmation.from_dpa(dpa=dpa) 79 80 @staticmethod 81 def create_from_json(json: dict) -> Confirmation: 82 return Confirmation.from_json(json=json) 83 84 85# Coordinator factories 86class CoordinatorAddrInfoFactory(BaseFactory): 87 88 @staticmethod 89 def create_from_dpa(dpa: bytes) -> c_responses.AddrInfoResponse: 90 return c_responses.AddrInfoResponse.from_dpa(dpa=dpa) 91 92 @staticmethod 93 def create_from_json(json: dict) -> c_responses.AddrInfoResponse: 94 return c_responses.AddrInfoResponse.from_json(json=json) 95 96 97class CoordinatorAuthorizeBondFactory(BaseFactory): 98 99 @staticmethod 100 def create_from_dpa(dpa: bytes) -> c_responses.AuthorizeBondResponse: 101 return c_responses.AuthorizeBondResponse.from_dpa(dpa=dpa) 102 103 @staticmethod 104 def create_from_json(json: dict) -> c_responses.AuthorizeBondResponse: 105 return c_responses.AuthorizeBondResponse.from_json(json=json) 106 107 108class CoordinatorBackupFactory(BaseFactory): 109 110 @staticmethod 111 def create_from_dpa(dpa: bytes) -> c_responses.BackupResponse: 112 return c_responses.BackupResponse.from_dpa(dpa=dpa) 113 114 @staticmethod 115 def create_from_json(json: dict) -> c_responses.BackupResponse: 116 return c_responses.BackupResponse.from_json(json=json) 117 118 119class CoordinatorBondedDevicesFactory(BaseFactory): 120 121 @staticmethod 122 def create_from_dpa(dpa: bytes) -> c_responses.BondedDevicesResponse: 123 return c_responses.BondedDevicesResponse.from_dpa(dpa=dpa) 124 125 @staticmethod 126 def create_from_json(json: dict) -> c_responses.BondedDevicesResponse: 127 return c_responses.BondedDevicesResponse.from_json(json=json) 128 129 130class CoordinatorBondNodeFactory(BaseFactory): 131 132 @staticmethod 133 def create_from_dpa(dpa: bytes) -> c_responses.BondNodeResponse: 134 return c_responses.BondNodeResponse.from_dpa(dpa=dpa) 135 136 @staticmethod 137 def create_from_json(json: dict) -> c_responses.BondNodeResponse: 138 return c_responses.BondNodeResponse.from_json(json=json) 139 140 141class CoordinatorClearAllBondsFactory(BaseFactory): 142 143 @staticmethod 144 def create_from_dpa(dpa: bytes) -> c_responses.ClearAllBondsResponse: 145 return c_responses.ClearAllBondsResponse.from_dpa(dpa=dpa) 146 147 @staticmethod 148 def create_from_json(json: dict) -> c_responses.ClearAllBondsResponse: 149 return c_responses.ClearAllBondsResponse.from_json(json=json) 150 151 152class CoordinatorDiscoveredDevicesFactory(BaseFactory): 153 154 @staticmethod 155 def create_from_dpa(dpa: bytes) -> c_responses.DiscoveredDevicesResponse: 156 return c_responses.DiscoveredDevicesResponse.from_dpa(dpa=dpa) 157 158 @staticmethod 159 def create_from_json(json: dict) -> c_responses.DiscoveredDevicesResponse: 160 return c_responses.DiscoveredDevicesResponse.from_json(json=json) 161 162 163class CoordinatorDiscoveryFactory(BaseFactory): 164 165 @staticmethod 166 def create_from_dpa(dpa: bytes) -> c_responses.DiscoveryResponse: 167 return c_responses.DiscoveryResponse.from_dpa(dpa=dpa) 168 169 @staticmethod 170 def create_from_json(json: dict) -> c_responses.DiscoveryResponse: 171 return c_responses.DiscoveryResponse.from_json(json=json) 172 173 174class CoordinatorRemoveBondFactory(BaseFactory): 175 176 @staticmethod 177 def create_from_dpa(dpa: bytes) -> c_responses.RemoveBondResponse: 178 return c_responses.RemoveBondResponse.from_dpa(dpa=dpa) 179 180 @staticmethod 181 def create_from_json(json: dict) -> c_responses.RemoveBondResponse: 182 return c_responses.RemoveBondResponse.from_json(json=json) 183 184 185class CoordinatorRestoreFactory(BaseFactory): 186 187 @staticmethod 188 def create_from_dpa(dpa: bytes) -> c_responses.RestoreResponse: 189 return c_responses.RestoreResponse.from_dpa(dpa=dpa) 190 191 @staticmethod 192 def create_from_json(json: dict) -> c_responses.RestoreResponse: 193 return c_responses.RestoreResponse.from_json(json=json) 194 195 196class CoordinatorSetDpaParamsFactory(BaseFactory): 197 198 @staticmethod 199 def create_from_dpa(dpa: bytes) -> c_responses.SetDpaParamsResponse: 200 return c_responses.SetDpaParamsResponse.from_dpa(dpa=dpa) 201 202 @staticmethod 203 def create_from_json(json: dict) -> c_responses.SetDpaParamsResponse: 204 return c_responses.SetDpaParamsResponse.from_json(json=json) 205 206 207class CoordinatorSetHopsFactory(BaseFactory): 208 209 @staticmethod 210 def create_from_dpa(dpa: bytes) -> c_responses.SetHopsResponse: 211 return c_responses.SetHopsResponse.from_dpa(dpa=dpa) 212 213 @staticmethod 214 def create_from_json(json: dict) -> c_responses.SetHopsResponse: 215 return c_responses.SetHopsResponse.from_json(json=json) 216 217 218class CoordinatorSetMIDFactory(BaseFactory): 219 220 @staticmethod 221 def create_from_dpa(dpa: bytes) -> c_responses.SetMidResponse: 222 return c_responses.SetMidResponse.from_dpa(dpa=dpa) 223 224 @staticmethod 225 def create_from_json(json: dict) -> c_responses.SetMidResponse: 226 return c_responses.SetMidResponse.from_json(json=json) 227 228 229class CoordinatorSmartConnectFactory(BaseFactory): 230 231 @staticmethod 232 def create_from_dpa(dpa: bytes) -> c_responses.SmartConnectResponse: 233 return c_responses.SmartConnectResponse.from_dpa(dpa=dpa) 234 235 @staticmethod 236 def create_from_json(json: dict) -> c_responses.SmartConnectResponse: 237 return c_responses.SmartConnectResponse.from_json(json=json) 238 239 240# EEEPROM factories 241class EeepromReadFactory(BaseFactory): 242 243 @staticmethod 244 def create_from_dpa(dpa: bytes) -> eeeprom_responses.ReadResponse: 245 return eeeprom_responses.ReadResponse.from_dpa(dpa=dpa) 246 247 @staticmethod 248 def create_from_json(json: dict) -> eeeprom_responses.ReadResponse: 249 return eeeprom_responses.ReadResponse.from_json(json=json) 250 251 252class EeepromWriteFactory(BaseFactory): 253 254 @staticmethod 255 def create_from_dpa(dpa: bytes) -> eeeprom_responses.WriteResponse: 256 return eeeprom_responses.WriteResponse.from_dpa(dpa=dpa) 257 258 @staticmethod 259 def create_from_json(json: dict) -> eeeprom_responses.WriteResponse: 260 return eeeprom_responses.WriteResponse.from_json(json=json) 261 262 263# EEPROM factories 264class EepromReadFactory(BaseFactory): 265 266 @staticmethod 267 def create_from_dpa(dpa: bytes) -> eeprom_responses.ReadResponse: 268 return eeprom_responses.ReadResponse.from_dpa(dpa=dpa) 269 270 @staticmethod 271 def create_from_json(json: dict) -> eeprom_responses.ReadResponse: 272 return eeprom_responses.ReadResponse.from_json(json=json) 273 274 275class EepromWriteFactory(BaseFactory): 276 277 @staticmethod 278 def create_from_dpa(dpa: bytes) -> eeprom_responses.WriteResponse: 279 return eeprom_responses.WriteResponse.from_dpa(dpa=dpa) 280 281 @staticmethod 282 def create_from_json(json: dict) -> eeprom_responses.WriteResponse: 283 return eeprom_responses.WriteResponse.from_json(json=json) 284 285 286# Exploration factories 287class ExplorationPeripheralEnumerationFactory(BaseFactory): 288 289 @staticmethod 290 def create_from_dpa(dpa: bytes) -> exploration_responses.PeripheralEnumerationResponse: 291 return exploration_responses.PeripheralEnumerationResponse.from_dpa(dpa=dpa) 292 293 @staticmethod 294 def create_from_json(json: dict) -> exploration_responses.PeripheralEnumerationResponse: 295 return exploration_responses.PeripheralEnumerationResponse.from_json(json=json) 296 297 298class ExplorationPeripheralInformationFactory(BaseFactory): 299 300 @staticmethod 301 def create_from_dpa(dpa: bytes) -> exploration_responses.PeripheralInformationResponse: 302 return exploration_responses.PeripheralInformationResponse.from_dpa(dpa=dpa) 303 304 @staticmethod 305 def create_from_json(json: dict) -> exploration_responses.PeripheralInformationResponse: 306 return exploration_responses.PeripheralInformationResponse.from_json(json=json) 307 308 309class ExplorationMorePeripheralsInformationFactory(BaseFactory): 310 311 @staticmethod 312 def create_from_dpa(dpa: bytes) -> exploration_responses.MorePeripheralsInformationResponse: 313 return exploration_responses.MorePeripheralsInformationResponse.from_dpa(dpa=dpa) 314 315 @staticmethod 316 def create_from_json(json: dict) -> exploration_responses.MorePeripheralsInformationResponse: 317 return exploration_responses.MorePeripheralsInformationResponse.from_json(json=json) 318 319 320# FRC factories 321class FrcSendFactory(BaseFactory): 322 323 @staticmethod 324 def create_from_dpa(dpa: bytes) -> frc_responses.SendResponse: 325 return frc_responses.SendResponse.from_dpa(dpa=dpa) 326 327 @staticmethod 328 def create_from_json(json: dict) -> frc_responses.SendResponse: 329 return frc_responses.SendResponse.from_json(json=json) 330 331 332class FrcExtraResultFactory(BaseFactory): 333 334 @staticmethod 335 def create_from_dpa(dpa: bytes) -> frc_responses.ExtraResultResponse: 336 return frc_responses.ExtraResultResponse.from_dpa(dpa=dpa) 337 338 @staticmethod 339 def create_from_json(json: dict) -> frc_responses.ExtraResultResponse: 340 return frc_responses.ExtraResultResponse.from_json(json=json) 341 342 343class FrcSendSelectiveFactory(BaseFactory): 344 345 @staticmethod 346 def create_from_dpa(dpa: bytes) -> frc_responses.SendSelectiveResponse: 347 return frc_responses.SendSelectiveResponse.from_dpa(dpa=dpa) 348 349 @staticmethod 350 def create_from_json(json: dict) -> frc_responses.SendSelectiveResponse: 351 return frc_responses.SendSelectiveResponse.from_json(json=json) 352 353 354class FrcSetFrcParamsFactory(BaseFactory): 355 356 @staticmethod 357 def create_from_dpa(dpa: bytes) -> frc_responses.SetFrcParamsResponse: 358 return frc_responses.SetFrcParamsResponse.from_dpa(dpa=dpa) 359 360 @staticmethod 361 def create_from_json(json: dict) -> frc_responses.SetFrcParamsResponse: 362 return frc_responses.SetFrcParamsResponse.from_json(json=json) 363 364 365# IO factories 366class IoDirectionFactory(BaseFactory): 367 368 @staticmethod 369 def create_from_dpa(dpa: bytes) -> io_responses.DirectionResponse: 370 return io_responses.DirectionResponse.from_dpa(dpa=dpa) 371 372 @staticmethod 373 def create_from_json(json: dict) -> io_responses.DirectionResponse: 374 return io_responses.DirectionResponse.from_json(json=json) 375 376 377class IoGetFactory(BaseFactory): 378 379 @staticmethod 380 def create_from_dpa(dpa: bytes) -> io_responses.GetResponse: 381 return io_responses.GetResponse.from_dpa(dpa=dpa) 382 383 @staticmethod 384 def create_from_json(json: dict) -> io_responses.GetResponse: 385 return io_responses.GetResponse.from_json(json=json) 386 387 388class IoSetFactory(BaseFactory): 389 390 @staticmethod 391 def create_from_dpa(dpa: bytes) -> io_responses.SetResponse: 392 return io_responses.SetResponse.from_dpa(dpa=dpa) 393 394 @staticmethod 395 def create_from_json(json: dict) -> io_responses.SetResponse: 396 return io_responses.SetResponse.from_json(json=json) 397 398 399# LEDG factories 400class LedgSetOnFactory(BaseFactory): 401 402 @staticmethod 403 def create_from_dpa(dpa: bytes) -> ledg_responses.SetOnResponse: 404 return ledg_responses.SetOnResponse.from_dpa(dpa) 405 406 @staticmethod 407 def create_from_json(json: dict) -> ledg_responses.SetOnResponse: 408 return ledg_responses.SetOnResponse.from_json(json) 409 410 411class LedgSetOffFactory(BaseFactory): 412 413 @staticmethod 414 def create_from_dpa(dpa: bytes) -> ledg_responses.SetOffResponse: 415 return ledg_responses.SetOffResponse.from_dpa(dpa) 416 417 @staticmethod 418 def create_from_json(json: dict) -> ledg_responses.SetOffResponse: 419 return ledg_responses.SetOffResponse.from_json(json) 420 421 422class LedgPulseFactory(BaseFactory): 423 424 @staticmethod 425 def create_from_dpa(dpa: bytes) -> ledg_responses.PulseResponse: 426 return ledg_responses.PulseResponse.from_dpa(dpa=dpa) 427 428 @staticmethod 429 def create_from_json(json: dict) -> ledg_responses.PulseResponse: 430 return ledg_responses.PulseResponse.from_json(json=json) 431 432 433class LedgFlashingFactory(BaseFactory): 434 435 @staticmethod 436 def create_from_dpa(dpa: bytes) -> ledg_responses.FlashingResponse: 437 return ledg_responses.FlashingResponse.from_dpa(dpa=dpa) 438 439 @staticmethod 440 def create_from_json(json: dict) -> ledg_responses.FlashingResponse: 441 return ledg_responses.FlashingResponse.from_json(json=json) 442 443 444# LEDR factories 445class LedrSetOnFactory(BaseFactory): 446 447 @staticmethod 448 def create_from_dpa(dpa: bytes) -> ledr_responses.SetOnResponse: 449 return ledr_responses.SetOnResponse.from_dpa(dpa) 450 451 @staticmethod 452 def create_from_json(json: dict) -> ledr_responses.SetOnResponse: 453 return ledr_responses.SetOnResponse.from_json(json) 454 455 456class LedrSetOffFactory(BaseFactory): 457 458 @staticmethod 459 def create_from_dpa(dpa: bytes) -> ledr_responses.SetOffResponse: 460 return ledr_responses.SetOffResponse.from_dpa(dpa) 461 462 @staticmethod 463 def create_from_json(json: dict) -> ledr_responses.SetOffResponse: 464 return ledr_responses.SetOffResponse.from_json(json) 465 466 467class LedrPulseFactory(BaseFactory): 468 469 @staticmethod 470 def create_from_dpa(dpa: bytes) -> ledr_responses.PulseResponse: 471 return ledr_responses.PulseResponse.from_dpa(dpa=dpa) 472 473 @staticmethod 474 def create_from_json(json: dict) -> ledr_responses.PulseResponse: 475 return ledr_responses.PulseResponse.from_json(json=json) 476 477 478class LedrFlashingFactory(BaseFactory): 479 480 @staticmethod 481 def create_from_dpa(dpa: bytes) -> ledr_responses.FlashingResponse: 482 return ledr_responses.FlashingResponse.from_dpa(dpa=dpa) 483 484 @staticmethod 485 def create_from_json(json: dict) -> ledr_responses.FlashingResponse: 486 return ledr_responses.FlashingResponse.from_json(json=json) 487 488 489# Node factories 490class NodeReadFactory(BaseFactory): 491 492 @staticmethod 493 def create_from_dpa(dpa: bytes) -> node_responses.ReadResponse: 494 return node_responses.ReadResponse.from_dpa(dpa=dpa) 495 496 @staticmethod 497 def create_from_json(json: dict) -> node_responses.ReadResponse: 498 return node_responses.ReadResponse.from_json(json=json) 499 500 501class NodeRemoveBondFactory(BaseFactory): 502 503 @staticmethod 504 def create_from_dpa(dpa: bytes) -> node_responses.RemoveBondResponse: 505 return node_responses.RemoveBondResponse.from_dpa(dpa=dpa) 506 507 @staticmethod 508 def create_from_json(json: dict) -> node_responses.RemoveBondResponse: 509 return node_responses.RemoveBondResponse.from_json(json=json) 510 511 512class NodeBackupFactory(BaseFactory): 513 514 @staticmethod 515 def create_from_dpa(dpa: bytes) -> node_responses.BackupResponse: 516 return node_responses.BackupResponse.from_dpa(dpa=dpa) 517 518 @staticmethod 519 def create_from_json(json: dict) -> node_responses.BackupResponse: 520 return node_responses.BackupResponse.from_json(json=json) 521 522 523class NodeRestoreFactory(BaseFactory): 524 525 @staticmethod 526 def create_from_dpa(dpa: bytes) -> node_responses.RestoreResponse: 527 return node_responses.RestoreResponse.from_dpa(dpa=dpa) 528 529 @staticmethod 530 def create_from_json(json: dict) -> node_responses.RestoreResponse: 531 return node_responses.RestoreResponse.from_json(json=json) 532 533 534class NodeValidateBondsFactory(BaseFactory): 535 536 @staticmethod 537 def create_from_dpa(dpa: bytes) -> node_responses.ValidateBondsResponse: 538 return node_responses.ValidateBondsResponse.from_dpa(dpa=dpa) 539 540 @staticmethod 541 def create_from_json(json: dict) -> node_responses.ValidateBondsResponse: 542 return node_responses.ValidateBondsResponse.from_json(json=json) 543 544 545# OS factories 546class OSReadFactory(BaseFactory): 547 548 @staticmethod 549 def create_from_dpa(dpa: bytes) -> os_responses.ReadResponse: 550 return os_responses.ReadResponse.from_dpa(dpa=dpa) 551 552 @staticmethod 553 def create_from_json(json: dict) -> os_responses.ReadResponse: 554 return os_responses.ReadResponse.from_json(json=json) 555 556 557class OSResetFactory(BaseFactory): 558 559 @staticmethod 560 def create_from_dpa(dpa: bytes) -> os_responses.ResetResponse: 561 return os_responses.ResetResponse.from_dpa(dpa=dpa) 562 563 @staticmethod 564 def create_from_json(json: dict) -> os_responses.ResetResponse: 565 return os_responses.ResetResponse.from_json(json=json) 566 567 568class OSRestartFactory(BaseFactory): 569 570 @staticmethod 571 def create_from_dpa(dpa: bytes) -> os_responses.RestartResponse: 572 return os_responses.RestartResponse.from_dpa(dpa=dpa) 573 574 @staticmethod 575 def create_from_json(json: dict) -> os_responses.RestartResponse: 576 return os_responses.RestartResponse.from_json(json=json) 577 578 579class OSReadTrConfFactory(BaseFactory): 580 581 @staticmethod 582 def create_from_dpa(dpa: bytes) -> os_responses.ReadTrConfResponse: 583 return os_responses.ReadTrConfResponse.from_dpa(dpa=dpa) 584 585 @staticmethod 586 def create_from_json(json: dict) -> os_responses.ReadTrConfResponse: 587 return os_responses.ReadTrConfResponse.from_json(json=json) 588 589 590class OSWriteTrConfFactory(BaseFactory): 591 592 @staticmethod 593 def create_from_dpa(dpa: bytes) -> os_responses.WriteTrConfResponse: 594 return os_responses.WriteTrConfResponse.from_dpa(dpa=dpa) 595 596 @staticmethod 597 def create_from_json(json: dict) -> os_responses.WriteTrConfResponse: 598 return os_responses.WriteTrConfResponse.from_json(json=json) 599 600 601class OsWriteTrConfByteFactory(BaseFactory): 602 603 @staticmethod 604 def create_from_dpa(dpa: bytes) -> os_responses.WriteTrConfByteResponse: 605 return os_responses.WriteTrConfByteResponse.from_dpa(dpa=dpa) 606 607 @staticmethod 608 def create_from_json(json: dict) -> os_responses.WriteTrConfByteResponse: 609 return os_responses.WriteTrConfByteResponse.from_json(json=json) 610 611 612class OSRfpgmFactory(BaseFactory): 613 614 @staticmethod 615 def create_from_dpa(dpa: bytes) -> os_responses.RfpgmResponse: 616 return os_responses.RfpgmResponse.from_dpa(dpa=dpa) 617 618 @staticmethod 619 def create_from_json(json: dict) -> os_responses.RfpgmResponse: 620 return os_responses.RfpgmResponse.from_json(json=json) 621 622 623class OSSleepFactory(BaseFactory): 624 625 @staticmethod 626 def create_from_dpa(dpa: bytes) -> os_responses.SleepResponse: 627 return os_responses.SleepResponse.from_dpa(dpa=dpa) 628 629 @staticmethod 630 def create_from_json(json: dict) -> os_responses.SleepResponse: 631 return os_responses.SleepResponse.from_json(json=json) 632 633 634class OSSetSecurityFactory(BaseFactory): 635 636 @staticmethod 637 def create_from_dpa(dpa: bytes) -> os_responses.SetSecurityResponse: 638 return os_responses.SetSecurityResponse.from_dpa(dpa=dpa) 639 640 @staticmethod 641 def create_from_json(json: dict) -> os_responses.SetSecurityResponse: 642 return os_responses.SetSecurityResponse.from_json(json=json) 643 644 645class OSBatchFactory(BaseFactory): 646 647 @staticmethod 648 def create_from_dpa(dpa: bytes) -> os_responses.BatchResponse: 649 return os_responses.BatchResponse.from_dpa(dpa=dpa) 650 651 @staticmethod 652 def create_from_json(json: dict) -> os_responses.BatchResponse: 653 return os_responses.BatchResponse.from_json(json=json) 654 655 656class OSSelectiveBatchFactory(BaseFactory): 657 658 @staticmethod 659 def create_from_dpa(dpa: bytes) -> os_responses.SelectiveBatchResponse: 660 return os_responses.SelectiveBatchResponse.from_dpa(dpa=dpa) 661 662 @staticmethod 663 def create_from_json(json: dict) -> os_responses.SelectiveBatchResponse: 664 return os_responses.SelectiveBatchResponse.from_json(json=json) 665 666 667class OSIndicateFactory(BaseFactory): 668 669 @staticmethod 670 def create_from_dpa(dpa: bytes) -> os_responses.IndicateResponse: 671 return os_responses.IndicateResponse.from_dpa(dpa=dpa) 672 673 @staticmethod 674 def create_from_json(json: dict) -> os_responses.IndicateResponse: 675 return os_responses.IndicateResponse.from_json(json=json) 676 677 678class OSFactorySettingsFactory(BaseFactory): 679 680 @staticmethod 681 def create_from_dpa(dpa: bytes) -> os_responses.FactorySettingsResponse: 682 return os_responses.FactorySettingsResponse.from_dpa(dpa=dpa) 683 684 @staticmethod 685 def create_from_json(json: dict) -> os_responses.FactorySettingsResponse: 686 return os_responses.FactorySettingsResponse.from_json(json=json) 687 688 689class OSTestRfSignalFactory(BaseFactory): 690 691 @staticmethod 692 def create_from_dpa(dpa: bytes) -> os_responses.TestRfSignalResponse: 693 return os_responses.TestRfSignalResponse.from_dpa(dpa=dpa) 694 695 @staticmethod 696 def create_from_json(json: dict) -> os_responses.TestRfSignalResponse: 697 return os_responses.TestRfSignalResponse.from_json(json=json) 698 699 700class OsLoadCodeFactory(BaseFactory): 701 702 @staticmethod 703 def create_from_dpa(dpa: bytes) -> os_responses.LoadCodeResponse: 704 return os_responses.LoadCodeResponse.from_dpa(dpa=dpa) 705 706 @staticmethod 707 def create_from_json(json: dict) -> os_responses.LoadCodeResponse: 708 return os_responses.LoadCodeResponse.from_json(json=json) 709 710 711# RAM factories 712class RamReadFactory(BaseFactory): 713 714 @staticmethod 715 def create_from_dpa(dpa: bytes) -> ram_responses.ReadResponse: 716 return ram_responses.ReadResponse.from_dpa(dpa=dpa) 717 718 @staticmethod 719 def create_from_json(json: dict) -> ram_responses.ReadResponse: 720 return ram_responses.ReadResponse.from_json(json=json) 721 722 723class RamWriteFactory(BaseFactory): 724 725 @staticmethod 726 def create_from_dpa(dpa: bytes) -> ram_responses.WriteResponse: 727 return ram_responses.WriteResponse.from_dpa(dpa=dpa) 728 729 @staticmethod 730 def create_from_json(json: dict) -> ram_responses.WriteResponse: 731 return ram_responses.WriteResponse.from_json(json=json) 732 733 734class RamReadAnyFactory(BaseFactory): 735 736 @staticmethod 737 def create_from_dpa(dpa: bytes) -> ram_responses.ReadAnyResponse: 738 return ram_responses.ReadAnyResponse.from_dpa(dpa=dpa) 739 740 @staticmethod 741 def create_from_json(json: dict) -> ram_responses.ReadAnyResponse: 742 return ram_responses.ReadAnyResponse.from_json(json=json) 743 744 745# Thermometer factories 746class ThermometerReadFactory(BaseFactory): 747 748 @staticmethod 749 def create_from_dpa(dpa: bytes) -> thermometer_responses.ReadResponse: 750 return thermometer_responses.ReadResponse.from_dpa(dpa=dpa) 751 752 @staticmethod 753 def create_from_json(json: dict) -> thermometer_responses.ReadResponse: 754 return thermometer_responses.ReadResponse.from_json(json=json) 755 756 757# UART factories 758class UartOpenFactory(BaseFactory): 759 760 @staticmethod 761 def create_from_dpa(dpa: bytes) -> uart_responses.OpenResponse: 762 return uart_responses.OpenResponse.from_dpa(dpa=dpa) 763 764 @staticmethod 765 def create_from_json(json: dict) -> uart_responses.OpenResponse: 766 return uart_responses.OpenResponse.from_json(json=json) 767 768 769class UartCloseFactory(BaseFactory): 770 771 @staticmethod 772 def create_from_dpa(dpa: bytes) -> uart_responses.CloseResponse: 773 return uart_responses.CloseResponse.from_dpa(dpa=dpa) 774 775 @staticmethod 776 def create_from_json(json: dict) -> uart_responses.CloseResponse: 777 return uart_responses.CloseResponse.from_json(json=json) 778 779 780class UartWriteReadFactory(BaseFactory): 781 782 @staticmethod 783 def create_from_dpa(dpa: bytes) -> uart_responses.WriteReadResponse: 784 return uart_responses.WriteReadResponse.from_dpa(dpa=dpa) 785 786 @staticmethod 787 def create_from_json(json: dict) -> uart_responses.WriteReadResponse: 788 return uart_responses.WriteReadResponse.from_json(json=json) 789 790 791class UartClearWriteReadFactory(BaseFactory): 792 793 @staticmethod 794 def create_from_dpa(dpa: bytes) -> uart_responses.ClearWriteReadResponse: 795 return uart_responses.ClearWriteReadResponse.from_dpa(dpa=dpa) 796 797 @staticmethod 798 def create_from_json(json: dict) -> uart_responses.ClearWriteReadResponse: 799 return uart_responses.ClearWriteReadResponse.from_json(json=json) 800 801 802# BinaryOutput factories 803class BinaryOutputEnumerateFactory(BaseFactory): 804 805 @staticmethod 806 def create_from_dpa(dpa: bytes) -> bo_responses.EnumerateResponse: 807 return bo_responses.EnumerateResponse.from_dpa(dpa=dpa) 808 809 @staticmethod 810 def create_from_json(json: dict) -> bo_responses.EnumerateResponse: 811 return bo_responses.EnumerateResponse.from_json(json=json) 812 813 814class BinaryOutputSetFactory(BaseFactory): 815 816 @staticmethod 817 def create_from_dpa(dpa: bytes) -> bo_responses.SetOutputResponse: 818 return bo_responses.SetOutputResponse.from_dpa(dpa=dpa) 819 820 @staticmethod 821 def create_from_json(json: dict) -> bo_responses.SetOutputResponse: 822 return bo_responses.SetOutputResponse.from_json(json=json) 823 824 825# Sensor factories 826class SensorEnumerateFactory(BaseFactory): 827 828 @staticmethod 829 def create_from_dpa(dpa: bytes) -> sensor_responses.EnumerateResponse: 830 return sensor_responses.EnumerateResponse.from_dpa(dpa=dpa) 831 832 @staticmethod 833 def create_from_json(json: dict) -> sensor_responses.EnumerateResponse: 834 return sensor_responses.EnumerateResponse.from_json(json=json) 835 836 837class SensorReadSensorsFactory(BaseFactory): 838 839 @staticmethod 840 def create_from_dpa(dpa: bytes) -> sensor_responses.ReadSensorsResponse: 841 return sensor_responses.ReadSensorsResponse.from_dpa(dpa=dpa) 842 843 @staticmethod 844 def create_from_json(json: dict) -> sensor_responses.ReadSensorsResponse: 845 return sensor_responses.ReadSensorsResponse.from_json(json=json) 846 847 848class SensorReadSensorsWithTypesFactory(BaseFactory): 849 850 @staticmethod 851 def create_from_dpa(dpa: bytes) -> sensor_responses.ReadSensorsWithTypesResponse: 852 return sensor_responses.ReadSensorsWithTypesResponse.from_dpa(dpa=dpa) 853 854 @staticmethod 855 def create_from_json(json: dict) -> sensor_responses.ReadSensorsWithTypesResponse: 856 return sensor_responses.ReadSensorsWithTypesResponse.from_json(json=json) 857 858 859class ResponseFactory: 860 """Response factory class.""" 861 862 _dpa_factories: dict = { 863 EmbedPeripherals.COORDINATOR: { 864 CoordinatorResponseCommands.ADDR_INFO: CoordinatorAddrInfoFactory(), 865 CoordinatorResponseCommands.AUTHORIZE_BOND: CoordinatorAuthorizeBondFactory(), 866 CoordinatorResponseCommands.BACKUP: CoordinatorBackupFactory(), 867 CoordinatorResponseCommands.BONDED_DEVICES: CoordinatorBondedDevicesFactory(), 868 CoordinatorResponseCommands.BOND_NODE: CoordinatorBondNodeFactory(), 869 CoordinatorResponseCommands.CLEAR_ALL_BONDS: CoordinatorClearAllBondsFactory(), 870 CoordinatorResponseCommands.DISCOVERED_DEVICES: CoordinatorDiscoveredDevicesFactory(), 871 CoordinatorResponseCommands.DISCOVERY: CoordinatorDiscoveryFactory(), 872 CoordinatorResponseCommands.REMOVE_BOND: CoordinatorRemoveBondFactory(), 873 CoordinatorResponseCommands.RESTORE: CoordinatorRestoreFactory(), 874 CoordinatorResponseCommands.SET_DPA_PARAMS: CoordinatorSetDpaParamsFactory(), 875 CoordinatorResponseCommands.SET_HOPS: CoordinatorSetHopsFactory(), 876 CoordinatorResponseCommands.SET_MID: CoordinatorSetMIDFactory(), 877 CoordinatorResponseCommands.SMART_CONNECT: CoordinatorSmartConnectFactory(), 878 }, 879 EmbedPeripherals.EEEPROM: { 880 EEEPROMResponseCommands.READ: EeepromReadFactory(), 881 EEEPROMResponseCommands.WRITE: EeepromWriteFactory(), 882 }, 883 EmbedPeripherals.EEPROM: { 884 EEPROMResponseCommands.READ: EepromReadFactory(), 885 EEPROMResponseCommands.WRITE: EepromWriteFactory(), 886 }, 887 EmbedPeripherals.EXPLORATION: { 888 ExplorationResponseCommands.PERIPHERALS_ENUMERATION_INFORMATION: ExplorationPeripheralEnumerationFactory(), 889 }, 890 EmbedPeripherals.FRC: { 891 FrcResponseCommands.SEND: FrcSendFactory(), 892 FrcResponseCommands.EXTRA_RESULT: FrcExtraResultFactory(), 893 FrcResponseCommands.SEND_SELECTIVE: FrcSendSelectiveFactory(), 894 FrcResponseCommands.SET_PARAMS: FrcSetFrcParamsFactory(), 895 }, 896 EmbedPeripherals.IO: { 897 IOResponseCommands.DIRECTION: IoDirectionFactory(), 898 IOResponseCommands.GET: IoGetFactory(), 899 IOResponseCommands.SET: IoSetFactory(), 900 }, 901 EmbedPeripherals.LEDG: { 902 LEDResponseCommands.SET_ON: LedgSetOnFactory(), 903 LEDResponseCommands.SET_OFF: LedgSetOffFactory(), 904 LEDResponseCommands.PULSE: LedgPulseFactory(), 905 LEDResponseCommands.FLASHING: LedgFlashingFactory(), 906 }, 907 EmbedPeripherals.LEDR: { 908 LEDResponseCommands.SET_ON: LedrSetOnFactory(), 909 LEDResponseCommands.SET_OFF: LedrSetOffFactory(), 910 LEDResponseCommands.PULSE: LedrPulseFactory(), 911 LEDResponseCommands.FLASHING: LedrFlashingFactory(), 912 }, 913 EmbedPeripherals.NODE: { 914 NodeResponseCommands.READ: NodeReadFactory(), 915 NodeResponseCommands.REMOVE_BOND: NodeRemoveBondFactory(), 916 NodeResponseCommands.BACKUP: NodeBackupFactory(), 917 NodeResponseCommands.RESTORE: NodeRestoreFactory(), 918 NodeResponseCommands.VALIDATE_BONDS: NodeValidateBondsFactory(), 919 }, 920 EmbedPeripherals.OS: { 921 OSResponseCommands.READ: OSReadFactory(), 922 OSResponseCommands.RESET: OSResetFactory(), 923 OSResponseCommands.RESTART: OSRestartFactory(), 924 OSResponseCommands.READ_CFG: OSReadTrConfFactory(), 925 OSResponseCommands.WRITE_CFG: OSWriteTrConfFactory(), 926 OSResponseCommands.WRITE_CFG_BYTE: OsWriteTrConfByteFactory(), 927 OSResponseCommands.RFPGM: OSRfpgmFactory(), 928 OSResponseCommands.SLEEP: OSSleepFactory(), 929 OSResponseCommands.SET_SECURITY: OSSetSecurityFactory(), 930 OSResponseCommands.BATCH: OSBatchFactory(), 931 OSResponseCommands.SELECTIVE_BATCH: OSSelectiveBatchFactory(), 932 OSResponseCommands.INDICATE: OSIndicateFactory(), 933 OSResponseCommands.FACTORY_SETTINGS: OSFactorySettingsFactory(), 934 OSResponseCommands.TEST_RF_SIGNAL: OSTestRfSignalFactory(), 935 OSResponseCommands.LOAD_CODE: OsLoadCodeFactory(), 936 }, 937 EmbedPeripherals.RAM: { 938 RAMResponseCommands.READ: RamReadFactory(), 939 RAMResponseCommands.WRITE: RamWriteFactory(), 940 RAMResponseCommands.READ_ANY: RamReadAnyFactory(), 941 }, 942 EmbedPeripherals.THERMOMETER: { 943 ThermometerResponseCommands.READ: ThermometerReadFactory(), 944 }, 945 EmbedPeripherals.UART: { 946 UartResponseCommands.OPEN: UartOpenFactory(), 947 UartResponseCommands.CLOSE: UartCloseFactory(), 948 UartResponseCommands.WRITE_READ: UartWriteReadFactory(), 949 UartResponseCommands.CLEAR_WRITE_READ: UartClearWriteReadFactory(), 950 }, 951 Standards.BINARY_OUTPUT: { 952 BinaryOutputResponseCommands.ENUMERATE_OUTPUTS: BinaryOutputEnumerateFactory(), 953 BinaryOutputResponseCommands.SET_OUTPUT: BinaryOutputSetFactory(), 954 }, 955 Standards.SENSOR: { 956 SensorResponseCommands.ENUMERATE: SensorEnumerateFactory(), 957 SensorResponseCommands.READ_SENSORS: SensorReadSensorsFactory(), 958 SensorResponseCommands.READ_SENSORS_WITH_TYPES: SensorReadSensorsWithTypesFactory(), 959 }, 960 } 961 """DPA factories, dictionary (pnum) of dictionaries (pcmd).""" 962 963 _json_factories: dict = { 964 GenericMessages.RAW: GenericResponseFactory(), 965 CoordinatorMessages.ADDR_INFO: CoordinatorAddrInfoFactory(), 966 CoordinatorMessages.AUTHORIZE_BOND: CoordinatorAuthorizeBondFactory(), 967 CoordinatorMessages.BACKUP: CoordinatorBackupFactory(), 968 CoordinatorMessages.BONDED_DEVICES: CoordinatorBondedDevicesFactory(), 969 CoordinatorMessages.BOND_NODE: CoordinatorBondNodeFactory(), 970 CoordinatorMessages.CLEAR_ALL_BONDS: CoordinatorClearAllBondsFactory(), 971 CoordinatorMessages.DISCOVERED_DEVICES: CoordinatorDiscoveredDevicesFactory(), 972 CoordinatorMessages.DISCOVERY: CoordinatorDiscoveryFactory(), 973 CoordinatorMessages.REMOVE_BOND: CoordinatorRemoveBondFactory(), 974 CoordinatorMessages.RESTORE: CoordinatorRestoreFactory(), 975 CoordinatorMessages.SET_DPA_PARAMS: CoordinatorSetDpaParamsFactory(), 976 CoordinatorMessages.SET_HOPS: CoordinatorSetHopsFactory(), 977 CoordinatorMessages.SET_MID: CoordinatorSetMIDFactory(), 978 CoordinatorMessages.SMART_CONNECT: CoordinatorSmartConnectFactory(), 979 EEEPROMMessages.READ: EeepromReadFactory(), 980 EEEPROMMessages.WRITE: EeepromWriteFactory(), 981 EEPROMMessages.READ: EepromReadFactory(), 982 EEPROMMessages.WRITE: EepromWriteFactory(), 983 ExplorationMessages.ENUMERATE: ExplorationPeripheralEnumerationFactory(), 984 ExplorationMessages.PERIPHERAL_INFORMATION: ExplorationPeripheralInformationFactory(), 985 ExplorationMessages.MORE_PERIPHERALS_INFORMATION: ExplorationMorePeripheralsInformationFactory(), 986 FrcMessages.SEND: FrcSendFactory(), 987 FrcMessages.EXTRA_RESULT: FrcExtraResultFactory(), 988 FrcMessages.SEND_SELECTIVE: FrcSendSelectiveFactory(), 989 FrcMessages.SET_PARAMS: FrcSetFrcParamsFactory(), 990 IOMessages.DIRECTION: IoDirectionFactory(), 991 IOMessages.GET: IoGetFactory(), 992 IOMessages.SET: IoSetFactory(), 993 LEDGMessages.SET_ON: LedgSetOnFactory(), 994 LEDGMessages.SET_OFF: LedgSetOffFactory(), 995 LEDGMessages.PULSE: LedgPulseFactory(), 996 LEDGMessages.FLASHING: LedgFlashingFactory(), 997 LEDRMessages.SET_ON: LedrSetOnFactory(), 998 LEDRMessages.SET_OFF: LedrSetOffFactory(), 999 LEDRMessages.PULSE: LedrPulseFactory(), 1000 LEDRMessages.FLASHING: LedrFlashingFactory(), 1001 NodeMessages.READ: NodeReadFactory(), 1002 NodeMessages.REMOVE_BOND: NodeRemoveBondFactory(), 1003 NodeMessages.BACKUP: NodeBackupFactory(), 1004 NodeMessages.RESTORE: NodeRestoreFactory(), 1005 NodeMessages.VALIDATE_BONDS: NodeValidateBondsFactory(), 1006 OSMessages.READ: OSReadFactory(), 1007 OSMessages.RESET: OSResetFactory(), 1008 OSMessages.RESTART: OSRestartFactory(), 1009 OSMessages.READ_CFG: OSReadTrConfFactory(), 1010 OSMessages.WRITE_CFG: OSWriteTrConfFactory(), 1011 OSMessages.WRITE_CFG_BYTE: OsWriteTrConfByteFactory(), 1012 OSMessages.RFPGM: OSRfpgmFactory(), 1013 OSMessages.SLEEP: OSSleepFactory(), 1014 OSMessages.SET_SECURITY: OSSetSecurityFactory(), 1015 OSMessages.BATCH: OSBatchFactory(), 1016 OSMessages.SELECTIVE_BATCH: OSSelectiveBatchFactory(), 1017 OSMessages.INDICATE: OSIndicateFactory(), 1018 OSMessages.FACTORY_SETTINGS: OSFactorySettingsFactory(), 1019 OSMessages.TEST_RF_SIGNAL: OSTestRfSignalFactory(), 1020 OSMessages.LOAD_CODE: OsLoadCodeFactory(), 1021 RAMMessages.READ: RamReadFactory(), 1022 RAMMessages.WRITE: RamWriteFactory(), 1023 ThermometerMessages.READ: ThermometerReadFactory(), 1024 UartMessages.OPEN: UartOpenFactory(), 1025 UartMessages.CLOSE: UartCloseFactory(), 1026 UartMessages.WRITE_READ: UartWriteReadFactory(), 1027 UartMessages.CLEAR_WRITE_READ: UartClearWriteReadFactory(), 1028 BinaryOutputMessages.ENUMERATE: BinaryOutputEnumerateFactory(), 1029 BinaryOutputMessages.SET_OUTPUT: BinaryOutputSetFactory(), 1030 SensorMessages.ENUMERATE: SensorEnumerateFactory(), 1031 SensorMessages.READ_SENSORS_WITH_TYPES: SensorReadSensorsWithTypesFactory(), 1032 } 1033 """JSON API factories, dictionary (message types).""" 1034 1035 @classmethod 1036 def get_factory_from_dpa(cls, pnum: Union[Peripheral, int], pcmd: Union[Command, int], 1037 allow_generic: bool = False) -> BaseFactory: 1038 """Find response factory by combination of pnum and pcmd. 1039 1040 Args: 1041 pnum (Union[Peripheral int]): Peripheral number. 1042 pcmd (Union[Command, int]): Peripheral command. 1043 allow_generic (bool): Use generic response factory if a matching factory for pnum and pcmd does not exist. 1044 1045 Returns: 1046 :obj:`BaseFactory`: Response factory. 1047 1048 Raises: 1049 UnsupportedPeripheralError: If pnum does not exist in response factories and allow_generic is False. 1050 UnsupportedPeripheralCommandError: If pcmd does not exist in response factories and allow_generic is False. 1051 """ 1052 if pnum in cls._dpa_factories: 1053 if pcmd in cls._dpa_factories[pnum]: 1054 return cls._dpa_factories[pnum][pcmd] 1055 else: 1056 if allow_generic: 1057 return GenericResponseFactory() 1058 else: 1059 raise UnsupportedPeripheralCommandError(f'Unknown or unsupported peripheral command: {pcmd}') 1060 else: 1061 if allow_generic: 1062 return GenericResponseFactory() 1063 else: 1064 raise UnsupportedPeripheralError(f'Unknown or unsupported peripheral: {pnum}') 1065 1066 @classmethod 1067 def get_factory_from_mtype(cls, message_type: Union[MessageType, str], msgid: Optional[str] = None) -> BaseFactory: 1068 """Find response factory by message type. 1069 1070 Args: 1071 message_type (Union[MessageType, str): Message type. 1072 msgid (str, optional): Message ID, used for error handling. 1073 1074 Returns: 1075 :obj:`BaseFactory`: Response factory. 1076 1077 Raises: 1078 UnsupportedMessageTypeError: If message type does not exist in response factories. 1079 """ 1080 if message_type in cls._json_factories: 1081 return cls._json_factories[message_type] 1082 raise UnsupportedMessageTypeError(f'Unknown or unsupported message type: {message_type}', msgid) 1083 1084 @classmethod 1085 def get_response_from_dpa(cls, dpa: bytes, allow_generic: bool = False) -> IResponse: 1086 """Process DPA response and return corresponding response message object. 1087 1088 Args: 1089 dpa (bytes): DPA response. 1090 allow_generic (bool): Use generic response class if pnum or pcmd is unknown. 1091 1092 Returns: 1093 :obj:`IResponse`: Response object. 1094 """ 1095 IResponse.validate_dpa_response(dpa) 1096 pnum = dpa[ResponsePacketMembers.PNUM] 1097 pcmd = dpa[ResponsePacketMembers.PCMD] 1098 rcode = dpa[ResponsePacketMembers.RCODE] 1099 if rcode == ResponseCodes.CONFIRMATION and len(dpa) == CONFIRMATION_PACKET_LEN: 1100 factory = ConfirmationFactory() 1101 elif pcmd <= REQUEST_PCMD_MAX and rcode >= ResponseCodes.ASYNC_RESPONSE: 1102 factory = AsyncResponseFactory() 1103 elif pnum <= PNUM_MAX and pcmd == ExplorationResponseCommands.PERIPHERALS_ENUMERATION_INFORMATION: 1104 factory = ExplorationPeripheralInformationFactory() 1105 elif pnum == BYTE_MAX and pcmd >= RESPONSE_PCMD_MIN and \ 1106 pcmd != ExplorationResponseCommands.PERIPHERALS_ENUMERATION_INFORMATION: 1107 factory = ExplorationMorePeripheralsInformationFactory() 1108 else: 1109 try: 1110 peripheral = Common.pnum_from_dpa(pnum) 1111 command = Common.response_pcmd_from_dpa(peripheral, pcmd) 1112 factory = cls.get_factory_from_dpa(peripheral, command, allow_generic=allow_generic) 1113 except (UnsupportedPeripheralError, UnsupportedPeripheralCommandError) as err: 1114 if not allow_generic: 1115 raise err 1116 factory = GenericResponseFactory() 1117 return factory.create_from_dpa(dpa) 1118 1119 @classmethod 1120 def get_response_from_json(cls, json: dict) -> IResponse: 1121 """Process JSON API response and return corresponding response message object. 1122 1123 Args: 1124 json (dict): JSON API response. 1125 Response: 1126 :obj:`IResponse`: Response object. 1127 """ 1128 msgid = Common.msgid_from_json(json) 1129 mtype = Common.mtype_str_from_json(json) 1130 if msgid == IResponse.ASYNC_MSGID and \ 1131 mtype in GenericMessages and GenericMessages(mtype) == GenericMessages.RAW: 1132 factory = AsyncResponseFactory() 1133 else: 1134 message = Common.string_to_mtype(mtype) 1135 factory = cls.get_factory_from_mtype(message, msgid) 1136 return factory.create_from_json(json)
class
ResponseFactory:
860class ResponseFactory: 861 """Response factory class.""" 862 863 _dpa_factories: dict = { 864 EmbedPeripherals.COORDINATOR: { 865 CoordinatorResponseCommands.ADDR_INFO: CoordinatorAddrInfoFactory(), 866 CoordinatorResponseCommands.AUTHORIZE_BOND: CoordinatorAuthorizeBondFactory(), 867 CoordinatorResponseCommands.BACKUP: CoordinatorBackupFactory(), 868 CoordinatorResponseCommands.BONDED_DEVICES: CoordinatorBondedDevicesFactory(), 869 CoordinatorResponseCommands.BOND_NODE: CoordinatorBondNodeFactory(), 870 CoordinatorResponseCommands.CLEAR_ALL_BONDS: CoordinatorClearAllBondsFactory(), 871 CoordinatorResponseCommands.DISCOVERED_DEVICES: CoordinatorDiscoveredDevicesFactory(), 872 CoordinatorResponseCommands.DISCOVERY: CoordinatorDiscoveryFactory(), 873 CoordinatorResponseCommands.REMOVE_BOND: CoordinatorRemoveBondFactory(), 874 CoordinatorResponseCommands.RESTORE: CoordinatorRestoreFactory(), 875 CoordinatorResponseCommands.SET_DPA_PARAMS: CoordinatorSetDpaParamsFactory(), 876 CoordinatorResponseCommands.SET_HOPS: CoordinatorSetHopsFactory(), 877 CoordinatorResponseCommands.SET_MID: CoordinatorSetMIDFactory(), 878 CoordinatorResponseCommands.SMART_CONNECT: CoordinatorSmartConnectFactory(), 879 }, 880 EmbedPeripherals.EEEPROM: { 881 EEEPROMResponseCommands.READ: EeepromReadFactory(), 882 EEEPROMResponseCommands.WRITE: EeepromWriteFactory(), 883 }, 884 EmbedPeripherals.EEPROM: { 885 EEPROMResponseCommands.READ: EepromReadFactory(), 886 EEPROMResponseCommands.WRITE: EepromWriteFactory(), 887 }, 888 EmbedPeripherals.EXPLORATION: { 889 ExplorationResponseCommands.PERIPHERALS_ENUMERATION_INFORMATION: ExplorationPeripheralEnumerationFactory(), 890 }, 891 EmbedPeripherals.FRC: { 892 FrcResponseCommands.SEND: FrcSendFactory(), 893 FrcResponseCommands.EXTRA_RESULT: FrcExtraResultFactory(), 894 FrcResponseCommands.SEND_SELECTIVE: FrcSendSelectiveFactory(), 895 FrcResponseCommands.SET_PARAMS: FrcSetFrcParamsFactory(), 896 }, 897 EmbedPeripherals.IO: { 898 IOResponseCommands.DIRECTION: IoDirectionFactory(), 899 IOResponseCommands.GET: IoGetFactory(), 900 IOResponseCommands.SET: IoSetFactory(), 901 }, 902 EmbedPeripherals.LEDG: { 903 LEDResponseCommands.SET_ON: LedgSetOnFactory(), 904 LEDResponseCommands.SET_OFF: LedgSetOffFactory(), 905 LEDResponseCommands.PULSE: LedgPulseFactory(), 906 LEDResponseCommands.FLASHING: LedgFlashingFactory(), 907 }, 908 EmbedPeripherals.LEDR: { 909 LEDResponseCommands.SET_ON: LedrSetOnFactory(), 910 LEDResponseCommands.SET_OFF: LedrSetOffFactory(), 911 LEDResponseCommands.PULSE: LedrPulseFactory(), 912 LEDResponseCommands.FLASHING: LedrFlashingFactory(), 913 }, 914 EmbedPeripherals.NODE: { 915 NodeResponseCommands.READ: NodeReadFactory(), 916 NodeResponseCommands.REMOVE_BOND: NodeRemoveBondFactory(), 917 NodeResponseCommands.BACKUP: NodeBackupFactory(), 918 NodeResponseCommands.RESTORE: NodeRestoreFactory(), 919 NodeResponseCommands.VALIDATE_BONDS: NodeValidateBondsFactory(), 920 }, 921 EmbedPeripherals.OS: { 922 OSResponseCommands.READ: OSReadFactory(), 923 OSResponseCommands.RESET: OSResetFactory(), 924 OSResponseCommands.RESTART: OSRestartFactory(), 925 OSResponseCommands.READ_CFG: OSReadTrConfFactory(), 926 OSResponseCommands.WRITE_CFG: OSWriteTrConfFactory(), 927 OSResponseCommands.WRITE_CFG_BYTE: OsWriteTrConfByteFactory(), 928 OSResponseCommands.RFPGM: OSRfpgmFactory(), 929 OSResponseCommands.SLEEP: OSSleepFactory(), 930 OSResponseCommands.SET_SECURITY: OSSetSecurityFactory(), 931 OSResponseCommands.BATCH: OSBatchFactory(), 932 OSResponseCommands.SELECTIVE_BATCH: OSSelectiveBatchFactory(), 933 OSResponseCommands.INDICATE: OSIndicateFactory(), 934 OSResponseCommands.FACTORY_SETTINGS: OSFactorySettingsFactory(), 935 OSResponseCommands.TEST_RF_SIGNAL: OSTestRfSignalFactory(), 936 OSResponseCommands.LOAD_CODE: OsLoadCodeFactory(), 937 }, 938 EmbedPeripherals.RAM: { 939 RAMResponseCommands.READ: RamReadFactory(), 940 RAMResponseCommands.WRITE: RamWriteFactory(), 941 RAMResponseCommands.READ_ANY: RamReadAnyFactory(), 942 }, 943 EmbedPeripherals.THERMOMETER: { 944 ThermometerResponseCommands.READ: ThermometerReadFactory(), 945 }, 946 EmbedPeripherals.UART: { 947 UartResponseCommands.OPEN: UartOpenFactory(), 948 UartResponseCommands.CLOSE: UartCloseFactory(), 949 UartResponseCommands.WRITE_READ: UartWriteReadFactory(), 950 UartResponseCommands.CLEAR_WRITE_READ: UartClearWriteReadFactory(), 951 }, 952 Standards.BINARY_OUTPUT: { 953 BinaryOutputResponseCommands.ENUMERATE_OUTPUTS: BinaryOutputEnumerateFactory(), 954 BinaryOutputResponseCommands.SET_OUTPUT: BinaryOutputSetFactory(), 955 }, 956 Standards.SENSOR: { 957 SensorResponseCommands.ENUMERATE: SensorEnumerateFactory(), 958 SensorResponseCommands.READ_SENSORS: SensorReadSensorsFactory(), 959 SensorResponseCommands.READ_SENSORS_WITH_TYPES: SensorReadSensorsWithTypesFactory(), 960 }, 961 } 962 """DPA factories, dictionary (pnum) of dictionaries (pcmd).""" 963 964 _json_factories: dict = { 965 GenericMessages.RAW: GenericResponseFactory(), 966 CoordinatorMessages.ADDR_INFO: CoordinatorAddrInfoFactory(), 967 CoordinatorMessages.AUTHORIZE_BOND: CoordinatorAuthorizeBondFactory(), 968 CoordinatorMessages.BACKUP: CoordinatorBackupFactory(), 969 CoordinatorMessages.BONDED_DEVICES: CoordinatorBondedDevicesFactory(), 970 CoordinatorMessages.BOND_NODE: CoordinatorBondNodeFactory(), 971 CoordinatorMessages.CLEAR_ALL_BONDS: CoordinatorClearAllBondsFactory(), 972 CoordinatorMessages.DISCOVERED_DEVICES: CoordinatorDiscoveredDevicesFactory(), 973 CoordinatorMessages.DISCOVERY: CoordinatorDiscoveryFactory(), 974 CoordinatorMessages.REMOVE_BOND: CoordinatorRemoveBondFactory(), 975 CoordinatorMessages.RESTORE: CoordinatorRestoreFactory(), 976 CoordinatorMessages.SET_DPA_PARAMS: CoordinatorSetDpaParamsFactory(), 977 CoordinatorMessages.SET_HOPS: CoordinatorSetHopsFactory(), 978 CoordinatorMessages.SET_MID: CoordinatorSetMIDFactory(), 979 CoordinatorMessages.SMART_CONNECT: CoordinatorSmartConnectFactory(), 980 EEEPROMMessages.READ: EeepromReadFactory(), 981 EEEPROMMessages.WRITE: EeepromWriteFactory(), 982 EEPROMMessages.READ: EepromReadFactory(), 983 EEPROMMessages.WRITE: EepromWriteFactory(), 984 ExplorationMessages.ENUMERATE: ExplorationPeripheralEnumerationFactory(), 985 ExplorationMessages.PERIPHERAL_INFORMATION: ExplorationPeripheralInformationFactory(), 986 ExplorationMessages.MORE_PERIPHERALS_INFORMATION: ExplorationMorePeripheralsInformationFactory(), 987 FrcMessages.SEND: FrcSendFactory(), 988 FrcMessages.EXTRA_RESULT: FrcExtraResultFactory(), 989 FrcMessages.SEND_SELECTIVE: FrcSendSelectiveFactory(), 990 FrcMessages.SET_PARAMS: FrcSetFrcParamsFactory(), 991 IOMessages.DIRECTION: IoDirectionFactory(), 992 IOMessages.GET: IoGetFactory(), 993 IOMessages.SET: IoSetFactory(), 994 LEDGMessages.SET_ON: LedgSetOnFactory(), 995 LEDGMessages.SET_OFF: LedgSetOffFactory(), 996 LEDGMessages.PULSE: LedgPulseFactory(), 997 LEDGMessages.FLASHING: LedgFlashingFactory(), 998 LEDRMessages.SET_ON: LedrSetOnFactory(), 999 LEDRMessages.SET_OFF: LedrSetOffFactory(), 1000 LEDRMessages.PULSE: LedrPulseFactory(), 1001 LEDRMessages.FLASHING: LedrFlashingFactory(), 1002 NodeMessages.READ: NodeReadFactory(), 1003 NodeMessages.REMOVE_BOND: NodeRemoveBondFactory(), 1004 NodeMessages.BACKUP: NodeBackupFactory(), 1005 NodeMessages.RESTORE: NodeRestoreFactory(), 1006 NodeMessages.VALIDATE_BONDS: NodeValidateBondsFactory(), 1007 OSMessages.READ: OSReadFactory(), 1008 OSMessages.RESET: OSResetFactory(), 1009 OSMessages.RESTART: OSRestartFactory(), 1010 OSMessages.READ_CFG: OSReadTrConfFactory(), 1011 OSMessages.WRITE_CFG: OSWriteTrConfFactory(), 1012 OSMessages.WRITE_CFG_BYTE: OsWriteTrConfByteFactory(), 1013 OSMessages.RFPGM: OSRfpgmFactory(), 1014 OSMessages.SLEEP: OSSleepFactory(), 1015 OSMessages.SET_SECURITY: OSSetSecurityFactory(), 1016 OSMessages.BATCH: OSBatchFactory(), 1017 OSMessages.SELECTIVE_BATCH: OSSelectiveBatchFactory(), 1018 OSMessages.INDICATE: OSIndicateFactory(), 1019 OSMessages.FACTORY_SETTINGS: OSFactorySettingsFactory(), 1020 OSMessages.TEST_RF_SIGNAL: OSTestRfSignalFactory(), 1021 OSMessages.LOAD_CODE: OsLoadCodeFactory(), 1022 RAMMessages.READ: RamReadFactory(), 1023 RAMMessages.WRITE: RamWriteFactory(), 1024 ThermometerMessages.READ: ThermometerReadFactory(), 1025 UartMessages.OPEN: UartOpenFactory(), 1026 UartMessages.CLOSE: UartCloseFactory(), 1027 UartMessages.WRITE_READ: UartWriteReadFactory(), 1028 UartMessages.CLEAR_WRITE_READ: UartClearWriteReadFactory(), 1029 BinaryOutputMessages.ENUMERATE: BinaryOutputEnumerateFactory(), 1030 BinaryOutputMessages.SET_OUTPUT: BinaryOutputSetFactory(), 1031 SensorMessages.ENUMERATE: SensorEnumerateFactory(), 1032 SensorMessages.READ_SENSORS_WITH_TYPES: SensorReadSensorsWithTypesFactory(), 1033 } 1034 """JSON API factories, dictionary (message types).""" 1035 1036 @classmethod 1037 def get_factory_from_dpa(cls, pnum: Union[Peripheral, int], pcmd: Union[Command, int], 1038 allow_generic: bool = False) -> BaseFactory: 1039 """Find response factory by combination of pnum and pcmd. 1040 1041 Args: 1042 pnum (Union[Peripheral int]): Peripheral number. 1043 pcmd (Union[Command, int]): Peripheral command. 1044 allow_generic (bool): Use generic response factory if a matching factory for pnum and pcmd does not exist. 1045 1046 Returns: 1047 :obj:`BaseFactory`: Response factory. 1048 1049 Raises: 1050 UnsupportedPeripheralError: If pnum does not exist in response factories and allow_generic is False. 1051 UnsupportedPeripheralCommandError: If pcmd does not exist in response factories and allow_generic is False. 1052 """ 1053 if pnum in cls._dpa_factories: 1054 if pcmd in cls._dpa_factories[pnum]: 1055 return cls._dpa_factories[pnum][pcmd] 1056 else: 1057 if allow_generic: 1058 return GenericResponseFactory() 1059 else: 1060 raise UnsupportedPeripheralCommandError(f'Unknown or unsupported peripheral command: {pcmd}') 1061 else: 1062 if allow_generic: 1063 return GenericResponseFactory() 1064 else: 1065 raise UnsupportedPeripheralError(f'Unknown or unsupported peripheral: {pnum}') 1066 1067 @classmethod 1068 def get_factory_from_mtype(cls, message_type: Union[MessageType, str], msgid: Optional[str] = None) -> BaseFactory: 1069 """Find response factory by message type. 1070 1071 Args: 1072 message_type (Union[MessageType, str): Message type. 1073 msgid (str, optional): Message ID, used for error handling. 1074 1075 Returns: 1076 :obj:`BaseFactory`: Response factory. 1077 1078 Raises: 1079 UnsupportedMessageTypeError: If message type does not exist in response factories. 1080 """ 1081 if message_type in cls._json_factories: 1082 return cls._json_factories[message_type] 1083 raise UnsupportedMessageTypeError(f'Unknown or unsupported message type: {message_type}', msgid) 1084 1085 @classmethod 1086 def get_response_from_dpa(cls, dpa: bytes, allow_generic: bool = False) -> IResponse: 1087 """Process DPA response and return corresponding response message object. 1088 1089 Args: 1090 dpa (bytes): DPA response. 1091 allow_generic (bool): Use generic response class if pnum or pcmd is unknown. 1092 1093 Returns: 1094 :obj:`IResponse`: Response object. 1095 """ 1096 IResponse.validate_dpa_response(dpa) 1097 pnum = dpa[ResponsePacketMembers.PNUM] 1098 pcmd = dpa[ResponsePacketMembers.PCMD] 1099 rcode = dpa[ResponsePacketMembers.RCODE] 1100 if rcode == ResponseCodes.CONFIRMATION and len(dpa) == CONFIRMATION_PACKET_LEN: 1101 factory = ConfirmationFactory() 1102 elif pcmd <= REQUEST_PCMD_MAX and rcode >= ResponseCodes.ASYNC_RESPONSE: 1103 factory = AsyncResponseFactory() 1104 elif pnum <= PNUM_MAX and pcmd == ExplorationResponseCommands.PERIPHERALS_ENUMERATION_INFORMATION: 1105 factory = ExplorationPeripheralInformationFactory() 1106 elif pnum == BYTE_MAX and pcmd >= RESPONSE_PCMD_MIN and \ 1107 pcmd != ExplorationResponseCommands.PERIPHERALS_ENUMERATION_INFORMATION: 1108 factory = ExplorationMorePeripheralsInformationFactory() 1109 else: 1110 try: 1111 peripheral = Common.pnum_from_dpa(pnum) 1112 command = Common.response_pcmd_from_dpa(peripheral, pcmd) 1113 factory = cls.get_factory_from_dpa(peripheral, command, allow_generic=allow_generic) 1114 except (UnsupportedPeripheralError, UnsupportedPeripheralCommandError) as err: 1115 if not allow_generic: 1116 raise err 1117 factory = GenericResponseFactory() 1118 return factory.create_from_dpa(dpa) 1119 1120 @classmethod 1121 def get_response_from_json(cls, json: dict) -> IResponse: 1122 """Process JSON API response and return corresponding response message object. 1123 1124 Args: 1125 json (dict): JSON API response. 1126 Response: 1127 :obj:`IResponse`: Response object. 1128 """ 1129 msgid = Common.msgid_from_json(json) 1130 mtype = Common.mtype_str_from_json(json) 1131 if msgid == IResponse.ASYNC_MSGID and \ 1132 mtype in GenericMessages and GenericMessages(mtype) == GenericMessages.RAW: 1133 factory = AsyncResponseFactory() 1134 else: 1135 message = Common.string_to_mtype(mtype) 1136 factory = cls.get_factory_from_mtype(message, msgid) 1137 return factory.create_from_json(json)
Response factory class.
@classmethod
def
get_factory_from_dpa( cls, pnum: Union[iqrfpy.enums.peripherals.Peripheral, int], pcmd: Union[iqrfpy.enums.commands.Command, int], allow_generic: bool = False) -> BaseFactory:
1036 @classmethod 1037 def get_factory_from_dpa(cls, pnum: Union[Peripheral, int], pcmd: Union[Command, int], 1038 allow_generic: bool = False) -> BaseFactory: 1039 """Find response factory by combination of pnum and pcmd. 1040 1041 Args: 1042 pnum (Union[Peripheral int]): Peripheral number. 1043 pcmd (Union[Command, int]): Peripheral command. 1044 allow_generic (bool): Use generic response factory if a matching factory for pnum and pcmd does not exist. 1045 1046 Returns: 1047 :obj:`BaseFactory`: Response factory. 1048 1049 Raises: 1050 UnsupportedPeripheralError: If pnum does not exist in response factories and allow_generic is False. 1051 UnsupportedPeripheralCommandError: If pcmd does not exist in response factories and allow_generic is False. 1052 """ 1053 if pnum in cls._dpa_factories: 1054 if pcmd in cls._dpa_factories[pnum]: 1055 return cls._dpa_factories[pnum][pcmd] 1056 else: 1057 if allow_generic: 1058 return GenericResponseFactory() 1059 else: 1060 raise UnsupportedPeripheralCommandError(f'Unknown or unsupported peripheral command: {pcmd}') 1061 else: 1062 if allow_generic: 1063 return GenericResponseFactory() 1064 else: 1065 raise UnsupportedPeripheralError(f'Unknown or unsupported peripheral: {pnum}')
Find response factory by combination of pnum and pcmd.
Arguments:
- pnum (Union[Peripheral int]): Peripheral number.
- pcmd (Union[Command, int]): Peripheral command.
- allow_generic (bool): Use generic response factory if a matching factory for pnum and pcmd does not exist.
Returns:
BaseFactory
: Response factory.
Raises:
- UnsupportedPeripheralError: If pnum does not exist in response factories and allow_generic is False.
- UnsupportedPeripheralCommandError: If pcmd does not exist in response factories and allow_generic is False.
@classmethod
def
get_factory_from_mtype( cls, message_type: Union[iqrfpy.enums.message_types.MessageType, str], msgid: Optional[str] = None) -> BaseFactory:
1067 @classmethod 1068 def get_factory_from_mtype(cls, message_type: Union[MessageType, str], msgid: Optional[str] = None) -> BaseFactory: 1069 """Find response factory by message type. 1070 1071 Args: 1072 message_type (Union[MessageType, str): Message type. 1073 msgid (str, optional): Message ID, used for error handling. 1074 1075 Returns: 1076 :obj:`BaseFactory`: Response factory. 1077 1078 Raises: 1079 UnsupportedMessageTypeError: If message type does not exist in response factories. 1080 """ 1081 if message_type in cls._json_factories: 1082 return cls._json_factories[message_type] 1083 raise UnsupportedMessageTypeError(f'Unknown or unsupported message type: {message_type}', msgid)
Find response factory by message type.
Arguments:
- message_type (Union[MessageType, str): Message type.
- msgid (str, optional): Message ID, used for error handling.
Returns:
BaseFactory
: Response factory.
Raises:
- UnsupportedMessageTypeError: If message type does not exist in response factories.
@classmethod
def
get_response_from_dpa( cls, dpa: bytes, allow_generic: bool = False) -> iqrfpy.iresponse.IResponse:
1085 @classmethod 1086 def get_response_from_dpa(cls, dpa: bytes, allow_generic: bool = False) -> IResponse: 1087 """Process DPA response and return corresponding response message object. 1088 1089 Args: 1090 dpa (bytes): DPA response. 1091 allow_generic (bool): Use generic response class if pnum or pcmd is unknown. 1092 1093 Returns: 1094 :obj:`IResponse`: Response object. 1095 """ 1096 IResponse.validate_dpa_response(dpa) 1097 pnum = dpa[ResponsePacketMembers.PNUM] 1098 pcmd = dpa[ResponsePacketMembers.PCMD] 1099 rcode = dpa[ResponsePacketMembers.RCODE] 1100 if rcode == ResponseCodes.CONFIRMATION and len(dpa) == CONFIRMATION_PACKET_LEN: 1101 factory = ConfirmationFactory() 1102 elif pcmd <= REQUEST_PCMD_MAX and rcode >= ResponseCodes.ASYNC_RESPONSE: 1103 factory = AsyncResponseFactory() 1104 elif pnum <= PNUM_MAX and pcmd == ExplorationResponseCommands.PERIPHERALS_ENUMERATION_INFORMATION: 1105 factory = ExplorationPeripheralInformationFactory() 1106 elif pnum == BYTE_MAX and pcmd >= RESPONSE_PCMD_MIN and \ 1107 pcmd != ExplorationResponseCommands.PERIPHERALS_ENUMERATION_INFORMATION: 1108 factory = ExplorationMorePeripheralsInformationFactory() 1109 else: 1110 try: 1111 peripheral = Common.pnum_from_dpa(pnum) 1112 command = Common.response_pcmd_from_dpa(peripheral, pcmd) 1113 factory = cls.get_factory_from_dpa(peripheral, command, allow_generic=allow_generic) 1114 except (UnsupportedPeripheralError, UnsupportedPeripheralCommandError) as err: 1115 if not allow_generic: 1116 raise err 1117 factory = GenericResponseFactory() 1118 return factory.create_from_dpa(dpa)
Process DPA response and return corresponding response message object.
Arguments:
- dpa (bytes): DPA response.
- allow_generic (bool): Use generic response class if pnum or pcmd is unknown.
Returns:
IResponse
: Response object.
1120 @classmethod 1121 def get_response_from_json(cls, json: dict) -> IResponse: 1122 """Process JSON API response and return corresponding response message object. 1123 1124 Args: 1125 json (dict): JSON API response. 1126 Response: 1127 :obj:`IResponse`: Response object. 1128 """ 1129 msgid = Common.msgid_from_json(json) 1130 mtype = Common.mtype_str_from_json(json) 1131 if msgid == IResponse.ASYNC_MSGID and \ 1132 mtype in GenericMessages and GenericMessages(mtype) == GenericMessages.RAW: 1133 factory = AsyncResponseFactory() 1134 else: 1135 message = Common.string_to_mtype(mtype) 1136 factory = cls.get_factory_from_mtype(message, msgid) 1137 return factory.create_from_json(json)
Process JSON API response and return corresponding response message object.
Arguments:
- json (dict): JSON API response.
Response:
IResponse
: Response object.
class
BaseFactory(abc.ABC):
38class BaseFactory(ABC): 39 """Response factory class abstraction.""" 40 41 @staticmethod 42 @abstractmethod 43 def create_from_dpa(dpa: bytes) -> IResponse: 44 """Returns a response object created from DPA message.""" 45 46 @staticmethod 47 @abstractmethod 48 def create_from_json(json: dict) -> IResponse: 49 """Returns a response object created from JSON API message."""
Response factory class abstraction.
41 @staticmethod 42 @abstractmethod 43 def create_from_dpa(dpa: bytes) -> IResponse: 44 """Returns a response object created from DPA message."""
Returns a response object created from DPA message.