Beispiel #1
0
  def set_address(self,address):
    self.sensor_address = address
    if 'eg-pm-usb' in self.get_hardware_type():
      self.device = (int(self.sensor_address)-1) / 4

    elif 'eg-pm-lan' in self.get_hardware_type():
      # Input format should be either:
      # - http://[HOST]#[POWER_SWITCH_NR]
      # - http://[HOST]/#[POWER_SWITCH_NR]
      # - http://[PASSWORD]@[HOST]#[POWER_SWITCH_NR]
      # - http://[PASSWORD]@[HOST]/#[POWER_SWITCH_NR]

      data = re.match(r"^http:\/\/((?P<passwd>[^@]+)@)?(?P<host>[^#\/]+)(\/)?#(?P<switch>[1-4])$",self.sensor_address)
      if data:
        data = data.groupdict()
        if 'passwd' not in data:
          data['passwd'] = ''

        try:
          # https://github.com/perryflynn/energenie-connect0r
          self.device = energenieconnector.EnergenieConnector('http://' + data['host'],data['passwd'])
          status = self.device.getstatus()

          if status['login'] == 1:
            if self.device.login():
              logger.info('Connection to remote Energenie LAN \'%s\' is successfull at location %s' % (self.get_name(), self.sensor_address))
              status = self.device.getstatus()

          if status['login'] != 0:
            logger.error('Could not login to the Energenie LAN device %s at location %s. Error status %s(%s)' % (self.get_name(),self.sensor_address,status['logintxt'],status['login']))
            self.device = None
        except Exception, ex:
          logger.exception('Could not login to the Energenie LAN device %s at location %s. Error status %s' % (self.get_name(),self.sensor_address,ex))
Beispiel #2
0
  def load_hardware(self):
    self.__device = None
    # Input format should be either:
    # - http://[HOST]#[POWER_SWITCH_NR]
    # - http://[HOST]/#[POWER_SWITCH_NR]
    # - http://[PASSWORD]@[HOST]#[POWER_SWITCH_NR]
    # - http://[PASSWORD]@[HOST]/#[POWER_SWITCH_NR]

    data = re.match(terrariumPowerSwitchEnergenieLAN.VALID_SOURCE,self.get_address())
    if data:
      data = data.groupdict()
      if 'passwd' not in data:
        data['passwd'] = ''

      try:
        # https://github.com/perryflynn/energenie-connect0r
        self.__device = energenieconnector.EnergenieConnector('http://' + data['host'],data['passwd'])
        status = self.__device.getstatus()

        if status['login'] == 1:
          if self.__device.login():
            logger.info('Connection to remote Energenie LAN \'%s\' is successfull at location %s' % (self.get_name(), self.get_address()))
            status = self.__device.getstatus()
            self.__device.logout()

        if status['login'] != 0:
          logger.error('Could not login to the Energenie LAN device %s at location %s. Error status %s(%s)' % (self.get_name(),self.get_address(),status['logintxt'],status['login']))
          self.__device = None

      except Exception as ex:
        logger.exception('Could not login to the Energenie LAN device %s at location %s. Error status %s' % (self.get_name(),self.get_address(),ex))
    def _load_hardware(self):
        # Input format should be either:
        # - http://[HOST]#[POWER_SWITCH_NR]
        # - http://[HOST]/#[POWER_SWITCH_NR]
        # - http://[PASSWORD]@[HOST]#[POWER_SWITCH_NR]
        # - http://[PASSWORD]@[HOST]/#[POWER_SWITCH_NR]

        address = self._address
        # TEMP data. Will be overwritten by the return value later on
        self._device['device'] = energenieconnector.EnergenieConnector(
            f'{address["protocol"]}://{address["host"]}', address['passwd'])
        if not self.__connect():
            raise terrariumRelayLoadingException(
                f'Failed loading relay {self}. Unable to login')

        # Create the cache key for caching the relay states.
        # This is usefull when there are more then 1 relay per hardware device.
        self.__cache_key = md5(
            f'{self.HARDWARE}{address["host"]}'.encode()).hexdigest()
        self.__cache = terrariumCache()

        self.__logout()

        return self._device['device']