Coverage for tests/tests_rf/virtual_rf/helpers.py: 0%

1#!/usr/bin/env python3

2"""RAMSES RF - a RAMSES-II protocol decoder & analyser."""

3

4 from ramses_rf import Device

5 from ramses_rf.binding_fsm import BindContext

6 from ramses_rf.device import Fakeable

7

8

9 def ensure_fakeable(dev: Device, make_fake: bool = True) -> None:

10 """If a Device is not Fakeable (i.e. Fakeable, not _faked), make it so."""

11

12 class _Fakeable(dev.__class__, Fakeable): # type: ignore[misc, name-defined]

13 pass

14

15 if isinstance(dev, Fakeable | _Fakeable):

16 return

17

18 dev.__class__ = _Fakeable

19 assert isinstance(dev, Fakeable)

20

21 setattr(dev, "_bind_context", BindContext(dev)) # noqa: B010

22

23 if make_fake:

24 dev._make_fake()