numat/productivity

get can try to read registers where none exist in the tags file

Opened this issue · 0 comments

The code in get() to determine if registers should be read has an overly-broad match:

    async def get(self) -> dict:
        """Get values of all tags with assigned modbus addresses.

        Returns:
            A dictionary of {tag: value} pairs.
        """
        result = {}
        if 'discrete_output' in self.addresses:
            result.update(await self._read_discrete(self.addresses['discrete_output']))
        if 'discrete_input' in self.addresses:
            result.update(await self._read_discrete(self.addresses['discrete_input'],
                                                    output=False))

        for type in ['input', 'holding']:
            if type in self.addresses:
                result.update(await self._read_registers(type))

for type in ['input'][...] will match discrete_input and therefore try to read input registers, even if none are present in the tags file / self.addresses. This will eventually raise ValueError("Missing data type.")