#!/usr/bin/python3
##############################################
#
# This is open source software licensed under the Apache License 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
##############################################

from plantgw.plantgw import PlantGateway, SensorConfig
import sys


def main():
    pg = PlantGateway()
    failed_sensors = pg.process_all()
    if len(failed_sensors) > 0:
        print('Could not get data from {}sensor(s): {}.'.format(
            len(failed_sensors),
            SensorConfig.get_name_string(failed_sensors)))
    pg.stop_client()
    # only count the sensors that are NOT fail silent
    num_failed = len([s for s in failed_sensors if not s.fail_silent])
    sys.exit(num_failed)


if __name__ == '__main__':
    main()
