Ejemplo n.º 1
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the RaspyRFM switch."""

    gateway_manufacturer = config.get(CONF_GATEWAY_MANUFACTURER,
                                      Manufacturer.SEEGEL_SYSTEME.value)
    gateway_model = config.get(CONF_GATEWAY_MODEL, GatewayModel.RASPYRFM.value)
    host = config[CONF_HOST]
    port = config.get(CONF_PORT)
    switches = config[CONF_SWITCHES]

    raspyrfm_client = RaspyRFMClient()
    gateway = raspyrfm_client.get_gateway(Manufacturer(gateway_manufacturer),
                                          GatewayModel(gateway_model), host,
                                          port)
    switch_entities = []
    for switch in switches:
        name = switch[CONF_NAME]
        controlunit_manufacturer = switch[CONF_CONTROLUNIT_MANUFACTURER]
        controlunit_model = switch[CONF_CONTROLUNIT_MODEL]
        channel_config = switch[CONF_CHANNEL_CONFIG]

        controlunit = raspyrfm_client.get_controlunit(
            Manufacturer(controlunit_manufacturer),
            ControlUnitModel(controlunit_model))

        controlunit.set_channel_config(**channel_config)

        switch = RaspyRFMSwitch(raspyrfm_client, name, gateway, controlunit)
        switch_entities.append(switch)

    add_entities(switch_entities)
    def test_random_controlunit_config(self):
        """
        Tests all device_implementations with random configurations.
        """

        rfm_client = RaspyRFMClient()

        rfm_client.get_supported_gateway_manufacturers()

        from raspyrfm_client.device_implementations.controlunit.base import ControlUnit

        def test_device(device: ControlUnit, gateway: Gateway):
            """
            Tests random device_implementations configurations for the specified device_implementations
            
            :param device: the device_implementations to test 
            """

            self.assertIsNotNone(device.get_manufacturer())
            self.assertIsNotNone(device.get_model())
            self.assertIsNotNone(device.get_supported_actions())

            channel_config_args = device.get_channel_config_args()

            # tests 50 randomly chosen configurations
            for i in range(50):
                channel_config = {}

                for arg in channel_config_args:
                    channel_config[arg] = rstr.xeger(channel_config_args[arg])

                device.set_channel_config(**channel_config)

                # test every action
                for action in device.get_supported_actions():
                    generated_code = gateway.generate_code(device, action)
                    self.assertIsNotNone(generated_code)

        def test_models(manufacturer: Manufacturer, gateways: [Gateway]):
            """
            Tests all models of the specified manufacturer
            
            :param gateways:
            :param manufacturer:  manufacturer to test all available models
            """
            for model in rfm_client.get_supported_controlunit_models(manufacturer):
                for gateway in gateways:
                    device = rfm_client.get_controlunit(manufacturer, model)
                    print("Testing Device: '%s %s' with Gateway: '%s %s'..." % (
                        device.get_manufacturer(), device.get_model(), gateway.get_manufacturer(), gateway.get_model()))
                    test_device(device, gateway)

        gateways = self.get_all_supported_gateways(rfm_client)

        for manufacturer in rfm_client.get_supported_controlunit_manufacturers():
            test_models(manufacturer, gateways)

        print("All random config device_implementations tests passed!")
    def get_all_supported_gateways(self, rfm_client: RaspyRFMClient) -> [Gateway]:
        gateways = []

        for manufacturer in rfm_client.get_supported_gateway_manufacturers():
            for model in rfm_client.get_supported_gateway_models(manufacturer):
                gateway = rfm_client.get_gateway(manufacturer, model)
                gateways.append(gateway)

        return gateways
    def test_gateway_init(self):

        rfm_client = RaspyRFMClient()

        from raspyrfm_client.device_implementations.gateway.base import Gateway

        def test_gateway(gateway: Gateway):
            self.assertIsNotNone(gateway)

        def test_models(manufacturer: Manufacturer):
            for model in rfm_client.get_supported_gateway_models(manufacturer):
                gateway = rfm_client.get_gateway(manufacturer, model)
                test_gateway(gateway)

        for manufacturer in rfm_client.get_supported_gateway_manufacturers():
            test_models(manufacturer)
Ejemplo n.º 5
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the RaspyRFM switch."""
    from raspyrfm_client import RaspyRFMClient
    from raspyrfm_client.device_implementations.controlunit. \
        controlunit_constants import ControlUnitModel
    from raspyrfm_client.device_implementations.gateway.manufacturer. \
        gateway_constants import GatewayModel
    from raspyrfm_client.device_implementations.manufacturer_constants \
        import Manufacturer

    gateway_manufacturer = config.get(CONF_GATEWAY_MANUFACTURER,
                                      Manufacturer.SEEGEL_SYSTEME.value)
    gateway_model = config.get(CONF_GATEWAY_MODEL, GatewayModel.RASPYRFM.value)
    host = config[CONF_HOST]
    port = config.get(CONF_PORT)
    switches = config[CONF_SWITCHES]

    raspyrfm_client = RaspyRFMClient()
    gateway = raspyrfm_client.get_gateway(Manufacturer(gateway_manufacturer),
                                          GatewayModel(gateway_model), host,
                                          port)
    switch_entities = []
    for switch in switches:
        name = switch[CONF_NAME]
        controlunit_manufacturer = switch[CONF_CONTROLUNIT_MANUFACTURER]
        controlunit_model = switch[CONF_CONTROLUNIT_MODEL]
        channel_config = switch[CONF_CHANNEL_CONFIG]

        controlunit = raspyrfm_client.get_controlunit(
            Manufacturer(controlunit_manufacturer),
            ControlUnitModel(controlunit_model))

        controlunit.set_channel_config(**channel_config)

        switch = RaspyRFMSwitch(raspyrfm_client, name, gateway, controlunit)
        switch_entities.append(switch)

    add_entities(switch_entities)
Ejemplo n.º 6
0
from raspyrfm_client import RaspyRFMClient
from raspyrfm_client.device_implementations.controlunit.actions import Action
from raspyrfm_client.device_implementations.controlunit.controlunit_constants import ControlUnitModel
from raspyrfm_client.device_implementations.gateway.manufacturer.gateway_constants import GatewayModel
from raspyrfm_client.device_implementations.manufacturer_constants import Manufacturer
""" RaspyRFM Client """
rfm_client = RaspyRFMClient()

print("Supported Gateways:")
rfm_client.list_supported_gateways()

print("")
print("Supported Controlunits:")
rfm_client.list_supported_controlunits()

raspyrfm = rfm_client.get_gateway(Manufacturer.SEEGEL_SYSTEME,
                                  GatewayModel.RASPYRFM, "192.168.2.10")

print("Host: " + str(raspyrfm.get_host()))
print("Port: " + str(raspyrfm.get_port()))
print("Manufacturer: " + str(raspyrfm.get_manufacturer()))
print("Model: " + str(raspyrfm.get_model()))
print("Firmware: " + str(raspyrfm.get_firmware_version()))
""" Brennenstuhl """
print("")

brennenstuhl_rcs1000 = rfm_client.get_controlunit(
    Manufacturer.BRENNENSTUHL, ControlUnitModel.RCS_1000_N_COMFORT)
brennenstuhl_rcs1000.set_channel_config(**{
    '1': 1,
    '2': 1,
Ejemplo n.º 7
0
from raspyrfm_client import RaspyRFMClient
from raspyrfm_client.device_implementations.controlunit.actions import Action
from raspyrfm_client.device_implementations.controlunit.controlunit_constants import ControlUnitModel
from raspyrfm_client.device_implementations.gateway.manufacturer.gateway_constants import GatewayModel
from raspyrfm_client.device_implementations.manufacturer_constants import Manufacturer

rfm_client = RaspyRFMClient()

print("Supported Gateways:")
rfm_client.list_supported_gateways()

print("")

print("Supported ControlUnits:")
rfm_client.list_supported_controlunits()

raspyrfm = rfm_client.get_gateway(Manufacturer.SEEGEL_SYSTEME,
                                  GatewayModel.RASPYRFM, "192.168.2.10")
itgw = rfm_client.get_gateway(Manufacturer.INTERTECHNO, GatewayModel.ITGW,
                              "192.168.2.70")

brennenstuhl_rcs1000 = rfm_client.get_controlunit(
    Manufacturer.BRENNENSTUHL, ControlUnitModel.RCS_1000_N_COMFORT)
brennenstuhl_rcs1000.set_channel_config(**{
    '1': 1,
    '2': 1,
    '3': 1,
    '4': 1,
    '5': 1,
    'CH': 'D'
})