Esempio n. 1
0
    def set_safe(self, name: str, value: NT_TYPES) -> None:
        entry = self._get_entry(name)

        # Calculated using Python type (bool, str, float)
        try:
            create_value_func: Callable[..., Value] = Value.getFactory(value)
        except ValueError as e:  # getFactory raises ValueError when it should be raising TypeError
            raise TypeError(*e.args)

        if entry is not None:
            # Calculated using NT type (NT_BOOLEAN, NT_STRING, NT_DOUBLE)
            if Value.getFactoryByType(entry.type) != create_value_func:
                # The factories don't match, which means the types don't match
                # Do not allow implicit type conversion
                raise TypeError("Existing type {} does not match: {}".format(
                    entry.type, type(value)))

        # Convert Python type into NT type
        nt_value: Value = create_value_func(value)

        # Returns False on error (type mismatch)
        successful = self.api.setEntryValue(self._get_path(name), nt_value)

        if not successful:
            raise TypeError("Existing type {} does not match: {}".format(
                entry.type, type(value)))
Esempio n. 2
0
    def reset(self):
        self.ntvalue = NetworkTables.getGlobalAutoUpdateValue(
            self.key, self.defaultValue, self.writeDefault)
        if self.persistent:
            self.ntvalue.setPersistent()

        # this is an optimization, but presumes the value type never changes
        self.mkv = Value.getFactoryByType(self.ntvalue._value[0])
Esempio n. 3
0
    def reset(self):
        self.ntvalue = NetworkTables.getGlobalAutoUpdateValue(
            self.key, self.defaultValue, self.writeDefault
        )
        if self.persistent:
            self.ntvalue.setPersistent()

        # this is an optimization, but presumes the value type never changes
        self.mkv = Value.getFactoryByType(self.ntvalue._value[0])