Beispiel #1
0
 def test_irrigate_zone(self):
     mock_response("01", pageNumber=0, commandEcho=6)
     mock_response("BF",
                   pageNumber=0,
                   activeStations=0b10000000000000000000000000000)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(True, rainbird.irrigate_zone(5, 30))
Beispiel #2
0
def _setup_controller(hass, controller_config, config):
    """Set up a controller."""
    server = controller_config[CONF_HOST]
    password = controller_config[CONF_PASSWORD]
    controller = RainbirdController(server, password)
    position = len(hass.data[DATA_RAINBIRD])
    try:
        controller.get_serial_number()
    except Exception as exc:  # pylint: disable=broad-except
        _LOGGER.error("Unable to setup controller: %s", exc)
        return False
    hass.data[DATA_RAINBIRD].append(controller)
    _LOGGER.debug("Rain Bird Controller %d set to: %s", position, server)
    for platform in PLATFORMS:
        discovery.load_platform(
            hass,
            platform,
            DOMAIN,
            {
                RAINBIRD_CONTROLLER: position,
                **controller_config
            },
            config,
        )
    return True
Beispiel #3
0
 def test_get_model_and_version(self):
     mock_response("82",
                   modelID=16,
                   protocolRevisionMajor=1,
                   protocolRevisionMinor=3)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(ModelAndVersion(16, 1, 3),
                      rainbird.get_model_and_version())
Beispiel #4
0
 def test_get_current_time(self):
     time = datetime.time()
     mock_response("90",
                   hour=time.hour,
                   minute=time.minute,
                   second=time.second)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(time, rainbird.get_current_time())
Beispiel #5
0
def setup(hass, config):
    """Set up the Rain Bird componenent."""
    conf = config[DOMAIN]
    server = conf.get(CONF_HOST)
    password = conf.get(CONF_PASSWORD)

    from pyrainbird import RainbirdController
    controller = RainbirdController()
    controller.setConfig(server, password)

    _LOGGER.debug("Rain Bird Controller set to: %s", server)

    initialstatus = controller.currentIrrigation()
    if initialstatus == -1:
        _LOGGER.error("Error getting state. Possible configuration issues")
        return False

    hass.data[DATA_RAINBIRD] = controller
    return True
Beispiel #6
0
def setup(hass, config):
    """Set up the Rain Bird componenent."""
    conf = config[DOMAIN]
    server = conf.get(CONF_HOST)
    password = conf.get(CONF_PASSWORD)

    from pyrainbird import RainbirdController
    controller = RainbirdController()
    controller.setConfig(server, password)

    _LOGGER.debug("Rain Bird Controller set to: %s", server)

    initialstatus = controller.currentIrrigation()
    if initialstatus == -1:
        _LOGGER.error("Error getting state. Possible configuration issues")
        return False

    hass.data[DATA_RAINBIRD] = controller
    return True
Beispiel #7
0
def setup_platform(hass, config, add_devices, discovery_info=None):
    """Set up Rain Bird switches over a Rain Bird controller."""
    server = config.get(CONF_HOST)
    password = config.get(CONF_PASSWORD)

    from pyrainbird import RainbirdController
    controller = RainbirdController(_LOGGER)
    controller.setConfig(server, password)

    _LOGGER.debug("Rain Bird Controller set to " + str(server))

    if controller.currentIrrigation() == -1:
        _LOGGER.error("Error getting state. Possible configuration issues")
        raise PlatformNotReady
    else:
        _LOGGER.debug("Initialized Rain Bird Controller")

    devices = []
    for dev_id, switch in config.get(CONF_SWITCHES).items():
        devices.append(RainBirdSwitch(controller, switch, dev_id))
    add_devices(devices, True)
Beispiel #8
0
 def test_set_program(self):
     mock_response("01", commandEcho=5)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(True, rainbird.set_program(5))
Beispiel #9
0
 def test_get_water_budget(self):
     mock_response("B0", programCode=1, seasonalAdjust=65)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(WaterBudget(1, 65), rainbird.water_budget(5))
Beispiel #10
0
 def test_get_current_date(self):
     date = datetime.date.today()
     mock_response("92", year=date.year, month=date.month, day=date.day)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(date, rainbird.get_current_date())
Beispiel #11
0
 def test_get_serial_number(self):
     mock_response("85", serialNumber=0x12635436566)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(0x12635436566, rainbird.get_serial_number())
Beispiel #12
0
 def test_get_command_support(self):
     mock_response("84", commandEcho=6, support=1)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(CommandSupport(1, 6),
                      rainbird.get_command_support(0x85))
Beispiel #13
0
 def test_get_rain_delay(self):
     mock_response("B6", delaySetting=16)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(16, rainbird.get_rain_delay())
Beispiel #14
0
 def _assert_zone_state(self, i, j):
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     mask_ = (1 << (i - 1)) * 0x1000000
     mock_response("BF", pageNumber=0, activeStations=mask_)
     self.assertEqual(i == j, rainbird.get_zone_state(j))
Beispiel #15
0
 def _assert_rain_sensor(self, state, expected):
     mock_response("BE", sensorState=state)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(expected, rainbird.get_rain_sensor_state())
Beispiel #16
0
 def test_not_acknowledge_response(self):
     with self.assertRaises(Exception):
         mock_response("00", commandEcho=17, NAKCode=28)
         rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
         self.assertEqual(False, rainbird.irrigate_zone(1, 30))
Beispiel #17
0
 def _assert_get_current_irrigation(self, state, expected):
     mock_response("C8", irrigationState=state)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(expected, rainbird.get_current_irrigation())
Beispiel #18
0
 def test_set_rain_delay(self):
     mock_response("01", pageNumber=0, commandEcho=6)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(True, rainbird.set_rain_delay(3))
Beispiel #19
0
 def test_test_zone(self):
     mock_response("01", commandEcho=6)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(True, rainbird.test_zone(6))
Beispiel #20
0
#!/usr/bin/env python3
import sys

from pyrainbird import RainbirdController
import logging
import os

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
ch.setFormatter(formatter)
logger.addHandler(ch)

logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("http.client")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
requests_log.addHandler(ch)

controller = RainbirdController(
    os.environ["RAINBIRD_SERVER"], os.environ["RAINBIRD_PASSWORD"]
)
print("%s\n" % controller.command(sys.argv[1], *sys.argv[2:]))
Beispiel #21
0
 def test_get_available_stations(self):
     mock_response("83", pageNumber=1, setStations=0x7F000000)
     rainbird = RainbirdController(MOCKED_RAINBIRD_URL, MOCKED_PASSWORD)
     self.assertEqual(AvailableStations("7f000000", 1),
                      rainbird.get_available_stations())
Beispiel #22
0
import logging
import os

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
ch.setFormatter(formatter)
logger.addHandler(ch)

password = "******"
encrypt = encryption.encrypt(
    '{"id":9,"jsonrpc":"2.0","method":"tunnelSip","params":{"data":"02","length":1}}',
    password,
)
print("%s\n" % encrypt)

decrypt = encryption.decrypt(encrypt, password)

print("%s\n" % decrypt)

controller = RainbirdController(os.environ["RAINBIRD_SERVER"],
                                os.environ["RAINBIRD_PASSWORD"])

print("%s\n" % controller.get_rain_delay())