Save sensors to file.

def save_sensors(self):
        """Save sensors to file."""
        if not self.need_save:
            return
        fname = os.path.realpath(self.persistence_file)
        exists = os.path.isfile(fname)
        dirname = os.path.dirname(fname)
        if (not os.access(dirname, os.W_OK) or exists and
                not os.access(fname, os.W_OK)):
            _LOGGER.error('Permission denied when writing to %s', fname)
            return
        split_fname = os.path.splitext(fname)
        tmp_fname = '{}.tmp{}'.format(split_fname[0], split_fname[1])
        _LOGGER.debug('Saving sensors to persistence file %s', fname)
        self._perform_file_action(tmp_fname, 'save')
        if exists:
            os.rename(fname, self.persistence_bak)
        os.rename(tmp_fname, fname)
        if exists:
            os.remove(self.persistence_bak)
        self.need_save = False