Exemplo n.º 1
0
def is_version(value):
    """Validate that value is a valid version string."""
    try:
        value = str(value)
        if parse_ver("1.4") > parse_ver(value):
            raise ValueError()
        return value
    except (AttributeError, TypeError, ValueError) as exc:
        raise vol.Invalid(f"{value} is not a valid version specifier") from exc
Exemplo n.º 2
0
def is_version(value):
    """Validate that value is a valid version string."""
    try:
        value = str(value)
        if not parse_ver('1.4') <= parse_ver(value):
            raise ValueError()
        return value
    except (AttributeError, TypeError, ValueError):
        raise vol.Invalid('{} is not a valid version specifier'.format(value))
Exemplo n.º 3
0
def get_const(protocol_version):
    """Return the const module for the protocol_version."""
    path = next((CONST_VERSIONS[const_version]
                 for const_version in sorted(CONST_VERSIONS, reverse=True)
                 if parse_ver(protocol_version) >= parse_ver(const_version)),
                'mysensors.const_14')
    if path in LOADED_CONST:
        return LOADED_CONST[path]
    const = import_module(path)
    LOADED_CONST[path] = const  # Cache the module
    return const
Exemplo n.º 4
0
def get_const(protocol_version):
    """Return the const module for the protocol_version."""
    version = protocol_version
    if parse_ver('1.5') <= parse_ver(version) < parse_ver('2.0'):
        path = 'mysensors.const_15'
    elif parse_ver(version) >= parse_ver('2.0'):
        path = 'mysensors.const_20'
    else:
        path = 'mysensors.const_14'
    if path in LOADED_CONST:
        return LOADED_CONST[path]
    const = import_module(path)
    LOADED_CONST[path] = const  # Cache the module
    return const
Exemplo n.º 5
0
 def is_sensor(self, sensorid, child_id=None):
     """Return True if a sensor and its child exist."""
     ret = sensorid in self.sensors
     if not ret:
         _LOGGER.warning('Node %s is unknown', sensorid)
     if ret and child_id is not None:
         ret = child_id in self.sensors[sensorid].children
         if not ret:
             _LOGGER.warning('Child %s is unknown', child_id)
     if not ret and parse_ver(self.protocol_version) >= parse_ver('2.0'):
         _LOGGER.info('Requesting new presentation for node %s', sensorid)
         msg = Message(gateway=self).modify(
             node_id=sensorid,
             child_id=SYSTEM_CHILD_ID,
             type=self.const.MessageType.internal,
             sub_type=self.const.Internal.I_PRESENTATION)
         if self._route_message(msg):
             self.fill_queue(msg.encode)
     return ret