def mapProtect(protect): event = [{ 'measurement': 'nest.protect', 'tags': { 'name': protect.name, 'where': protect.where, 'serial': protect.serial, 'product_id': protect.product_id, }, 'fields': { 'auto_away': boolify(protect.auto_away), 'battery_level': float(protect.battery_level), 'co_blame_duration': protect.co_blame_duration, 'co_blame_threshold': protect.co_blame_threshold, 'co_previous_peak': protect.co_previous_peak, 'co_status': protect.co_status, 'smoke_status': protect.smoke_status, 'component_als_test_passed': boolify(protect.component_als_test_passed), # noqa 'component_co_test_passed': boolify(protect.component_co_test_passed), # noqa 'component_heat_test_passed': boolify(protect.component_heat_test_passed), # noqa 'component_hum_test_passed': boolify(protect.component_hum_test_passed), # noqa 'component_led_test_passed': boolify(protect.component_led_test_passed), # noqa 'component_pir_test_passed': boolify(protect.component_pir_test_passed), # noqa 'component_smoke_test_passed': boolify(protect.component_smoke_test_passed), # noqa 'component_temp_test_passed': boolify(protect.component_temp_test_passed), # noqa 'component_us_test_passed': boolify(protect.component_us_test_passed), # noqa 'component_wifi_test_passed': boolify(protect.component_wifi_test_passed), # noqa 'gesture_hush_enable': boolify(protect.gesture_hush_enable), 'heads_up_enable': boolify(protect.heads_up_enable), 'home_alarm_link_capable': boolify(protect.home_alarm_link_capable), 'home_alarm_link_connected': boolify(protect.home_alarm_link_connected), # noqa 'hushed_state': boolify(protect.hushed_state), 'latest_manual_test_cancelled': boolify(protect.latest_manual_test_cancelled), # noqa 'line_power_present': boolify(protect.line_power_present), 'night_light_continuous': boolify(protect.night_light_continuous), # noqa 'night_light_enable': boolify(protect.night_light_enable), 'ntp_green_led_enable': boolify(protect.ntp_green_led_enable), # noqa 'steam_detection_enable': boolify(protect.steam_detection_enable), # noqa 'wired_led_enable': boolify(protect.wired_led_enable), 'description': protect.description, 'software_version': protect.software_version, 'wifi_ip_address': protect.wifi_ip_address, 'wifi_mac_address': protect.wifi_mac_address, 'thread_mac_address': protect.thread_mac_address, 'battery_health_state': protect.battery_health_state, 'capability_level': protect.capability_level, 'certification_body': protect.certification_body, 'creation_time': epoch2date(protect.creation_time/1000), 'home_alarm_link_type': protect.home_alarm_link_type, 'latest_manual_test_end_utc_secs': protect.latest_manual_test_end_utc_secs, # noqa 'latest_manual_test_start_utc_secs': protect.latest_manual_test_start_utc_secs, # noqa 'replace_by_date_utc_secs': epoch2date(protect.replace_by_date_utc_secs), # noqa 'co_sequence_number': protect.co_sequence_number, 'smoke_sequence_number': protect.smoke_sequence_number, 'wired_or_battery': protect.wired_or_battery } }] return event
def mapFeature(feature): event = [{ 'measurement': 'usgs.earthquake.feature', # Time Series Name 'tags': { 'type': feature['properties']['type'], 'gtype': feature['geometry']['type'], 'types': feature['properties']['types'], 'magType': feature['properties']['magType'], 'tsunami': feature['properties']['tsunami'], 'code': feature['properties']['code'], 'net': feature['properties']['net'], 'nst': feature['properties']['nst'], 'sources': feature['properties']['sources'], 'alert': feature['properties']['alert'], }, 'fields': { 'long': float(feature['geometry']['coordinates'][0]), 'lat': float(feature['geometry']['coordinates'][1]), 'depth': float(feature['geometry']['coordinates'][2]), 'felt': feature['properties']['felt'], 'sig': feature['properties']['sig'], 'dmin': feature['properties']['dmin'], 'id': feature['id'], 'status': feature['properties']['status'], 'title': feature['properties']['title'], 'place': feature['properties']['place'], 'status': feature['properties']['status'], 'time': epoch2date(feature['properties']['time'] / 1000), 'updated': epoch2date(feature['properties']['updated'] / 1000), 'tz': feature['properties']['tz'], 'ids': feature['properties']['ids'], } }] fields = event[0]['fields'] # Optional fields if feature['properties']['felt'] is not None: fields['felt'] = float(feature['properties']['felt']) if feature['properties']['gap'] is not None: fields['gap'] = float(feature['properties']['gap']) if feature['properties']['rms'] is not None: fields['rms'] = float(feature['properties']['rms']) if feature['properties']['mag'] is not None: fields['mag'] = float(feature['properties']['mag']) if feature['properties']['cdi'] is not None: fields['cdi'] = float(feature['properties']['cdi']) if feature['properties']['mag'] is not None: fields['mag'] = float(feature['properties']['mag']) return event
def mapSensor(sensor): event = [{ 'measurement': 'ubnt.mfi.sensor', 'tags': { }, 'fields': { } }] fields = event[0]['fields'] tags = event[0]['tags'] for key in sensor.keys(): if key in ['_id', 'label', 'mac', 'model', 'port', 'tag']: tags[key] = sensor[key] elif 'time' in key: fields[key] = epoch2date(sensor[key]/1000) else: try: fields[key] = float(sensor[key]) if key == 'temperature': fields['temperatureF'] = CtoF(sensor[key]) except ValueError: fields[key] = sensor[key] except TypeError: fields[key] = None return event
def mapStation(station): return [{ 'measurement': 'netatmo.station', 'tags': { 'id': station['_id'], 'station_name': station['station_name'], 'module_name': station['module_name'], 'firmware': int(station['firmware']), 'type': station['type'], }, 'fields': { 'wifi_status': int(station['wifi_status']), } }, { 'measurement': 'netatmo.module', 'tags': { 'id': station['_id'], 'station_name': station['station_name'], 'module_name': station['module_name'], 'firmware': int(station['firmware']), 'type': station['type'], # 'pressure_trend': station['dashboard_data']['pressure_trend'], # 'temp_trend': station['dashboard_data']['temp_trend'], }, 'fields': { 'co2_calibrating': station['co2_calibrating'], 'pressure': station['dashboard_data']['Pressure'], 'abs_pressure': station['dashboard_data']['AbsolutePressure'], 'pressurei': mBtoiHg(station['dashboard_data']['Pressure']), 'abs_pressurei': mBtoiHg(station['dashboard_data']['AbsolutePressure']), # noqa 'co2': int(station['dashboard_data']['CO2']), 'humidity': int(station['dashboard_data']['Humidity']), 'noise': int(station['dashboard_data']['Noise']), 'temp': station['dashboard_data']['Temperature'], 'max_temp': station['dashboard_data']['max_temp'], 'min_temp': station['dashboard_data']['min_temp'], 'tempf': CtoF(station['dashboard_data']['Temperature']), 'max_tempf': CtoF(station['dashboard_data']['max_temp']), 'min_tempf': CtoF(station['dashboard_data']['min_temp']), 'date_max_temp': epoch2date(station['dashboard_data']['date_max_temp']), 'date_min_temp': epoch2date(station['dashboard_data']['date_min_temp']), } }]
def mapMetadata(metadata): event = [{ 'measurement': 'usgs.earthquake.metadata', # Time Series Name 'tags': { 'title': metadata['title'], 'api': metadata['api'], 'status': metadata['status'], }, 'fields': { 'generated': epoch2date(metadata['generated'] / 1000), 'count': metadata['count'] } }] return event
def mapThermostat(thermostat): if thermostat.away_temperature[1] is not None: away_tempC = (float)('%0.1f' % thermostat.away_temperature[1]) away_tempF = (float)('%0.1f' % CtoF(thermostat.away_temperature[1])) else: away_tempC = 'Null' away_tempF = 'Null' event = [{ 'measurement': 'nest.thermostat', 'tags': { 'name': thermostat.name, 'where': thermostat.where, 'serial': thermostat.serial, }, 'fields': { 'last_ip': thermostat.last_ip, 'local_ip': thermostat.local_ip, 'mode': thermostat.mode, 'last_connection': epoch2date(thermostat.last_connection/1000), 'error_code': thermostat.error_code, 'fan': boolify(thermostat.fan), 'temperature_C': (float)('%0.1f' % thermostat.temperature), 'temperature_F': (float)('%0.1f' % CtoF(thermostat.temperature)), 'humidity': thermostat.humidity, 'target_C': (float)('%0.1f' % thermostat.target), 'target_F': (float)('%0.1f' % CtoF(thermostat.target)), 'away_low_C': (float)('%0.1f' % thermostat.away_temperature[0]), 'away_low_F': (float)('%0.1f' % CtoF(thermostat.away_temperature[0])), # noqa 'away_high_C': away_tempC, 'away_high_F': away_tempF, 'hvac_ac_state': boolify(thermostat.hvac_ac_state), 'hvac_cool_x2_state': boolify(thermostat.hvac_cool_x2_state), 'hvac_heater_state': boolify(thermostat.hvac_heater_state), 'hvac_aux_heater_state': boolify(thermostat.hvac_aux_heater_state), 'hvac_heat_x2_state': boolify(thermostat.hvac_heat_x2_state), 'hvac_heat_x3_state': boolify(thermostat.hvac_heat_x3_state), 'hvac_alt_heat_state': boolify(thermostat.hvac_alt_heat_state), 'hvac_alt_heat_x2_state': boolify(thermostat.hvac_alt_heat_x2_state), # noqa 'hvac_emer_heat_state': boolify(thermostat.hvac_emer_heat_state), 'online': boolify(thermostat.online), 'battery_level': float(thermostat.battery_level) } }] return event
def mapSensor(sensor): event = [{'measurement': 'ubnt.mfi.sensor', 'tags': {}, 'fields': {}}] fields = event[0]['fields'] tags = event[0]['tags'] for key in sensor.keys(): if key in ['_id', 'label', 'mac', 'model', 'port', 'tag']: tags[key] = sensor[key] elif 'time' in key: fields[key] = epoch2date(sensor[key] / 1000) else: try: fields[key] = float(sensor[key]) if key == 'temperature': fields['temperatureF'] = CtoF(sensor[key]) except ValueError: fields[key] = sensor[key] except TypeError: fields[key] = None return event
def mapModule(station, module): # This part of the event mapping is constant accross module types event = [{ 'measurement': 'netatmo.module', 'tags': { 'id': module['_id'], 'station_name': station['station_name'], 'module_name': module['module_name'], 'firmware': int(module['firmware']), 'type': module['type'], }, 'fields': { 'battery_vp': int(module['battery_vp']), 'rf_status': int(module['rf_status']), } }] fields = event[0]['fields'] dashboard = module['dashboard_data'] # Now add module type specific mappings if module['type'] in ['NAModule1', 'NAModule4']: # Outdoor & Indoor fields['date_max_temp'] = epoch2date(dashboard['date_max_temp']) fields['date_min_temp'] = epoch2date(dashboard['date_min_temp']) fields['humidity'] = int(dashboard['Humidity']) fields['temp'] = dashboard['Temperature'] fields['max_temp'] = dashboard['max_temp'] fields['min_temp'] = dashboard['min_temp'] fields['tempf'] = CtoF(dashboard['Temperature']) fields['max_tempf'] = CtoF(dashboard['max_temp']) fields['min_tempf'] = CtoF(dashboard['min_temp']) elif module['type'] == 'NAModule2': # Wind fields['wind_str'] = float(dashboard['WindStrength']) fields['wind_angle'] = float(dashboard['WindAngle']) fields['gust_str'] = float(dashboard['GustStrength']) fields['gust_angle'] = float(dashboard['GustAngle']) fields['max_wind_str'] = float(dashboard['max_wind_str']) fields['max_wind_angle'] = float(dashboard['max_wind_angle']) # { "_id": "06:00:00:00:f9:0a", # "battery_percent": 100.0, # "battery_vp": 6403.0, # "dashboard_data": # { "GustAngle": 243.0, # "GustStrength": 5.0, # "WindAngle": 237.0, # "WindHistoric": # [{ "WindAngle": 270.0, # "WindStrength": 2.0, # "time_utc": 1458409515.0}, # { "WindAngle": 270.0, # "WindStrength": 2.0, # "time_utc": 1458409817.0}, # { "WindAngle": 252.0, # "WindStrength": 2.0, # "time_utc": 1458410117.0}, # { "WindAngle": 249.0, # "WindStrength": 2.0, # "time_utc": 1458410418.0}, # { "WindAngle": 244.0, # "WindStrength": 2.0, # "time_utc": 1458410726.0}, # { "WindAngle": 270.0, # "WindStrength": 2.0, # "time_utc": 1458411027.0}, # { "WindAngle": 249.0, # "WindStrength": 2.0, # "time_utc": 1458411329.0}, # { "WindAngle": 236.0, # "WindStrength": 3.0, # "time_utc": 1458411630.0}, # { "WindAngle": 200.0, # "WindStrength": 2.0, # "time_utc": 1458411930.0}, # { "WindAngle": 225.0, # "WindStrength": 2.0, # "time_utc": 1458412232.0}, # { "WindAngle": 206.0, # "WindStrength": 2.0, # "time_utc": 1458412533.0}, # { "WindAngle": 237.0, # "WindStrength": 2.0, # "time_utc": 1458412834.0}], # "WindStrength": 2.0, # "date_max_temp": 1458370953.0, # "date_max_wind_str": 1458398980.0, # "date_min_temp": 1458370953.0, # "max_temp": 0.0, # "max_wind_angle": 259.0, # "max_wind_str": 6.0, # "min_temp": 0.0, # "time_utc": 1458412834.0}, # "data_type": ["Wind"], # "firmware": 14.0, # "last_message": 1458412847.0, # "last_seen": 1458412847.0, # "last_setup": 1458092732.0, # "module_name": "BBQ", # "rf_status": 66.0, # "type": "NAModule2"} elif module['type'] == 'NAModule3': # Rain fields['rain'] = dashboard['Rain'] fields['sum_rain_1'] = dashboard['sum_rain_1'] fields['sum_rain_24'] = dashboard['sum_rain_24'] fields['raini'] = mmtoin(dashboard['Rain']) fields['sum_rain_1i'] = mmtoin(dashboard['sum_rain_1']) fields['sum_rain_24i'] = mmtoin(dashboard['sum_rain_24']) if module['type'] == 'NAModule4': # Additional for Indoor # tags['temp_trend'] = dashboard['temp_trend'] fields['co2'] = int(dashboard['CO2']) return event
def mapStation(station): return [ { 'measurement': 'netatmo.station', 'tags': { 'id': station['_id'], 'station_name': station['station_name'], 'module_name': station['module_name'], 'firmware': int(station['firmware']), 'type': station['type'], }, 'fields': { 'wifi_status': int(station['wifi_status']), } }, { 'measurement': 'netatmo.module', 'tags': { 'id': station['_id'], 'station_name': station['station_name'], 'module_name': station['module_name'], 'firmware': int(station['firmware']), 'type': station['type'], # 'pressure_trend': station['dashboard_data']['pressure_trend'], # 'temp_trend': station['dashboard_data']['temp_trend'], }, 'fields': { 'co2_calibrating': station['co2_calibrating'], 'pressure': station['dashboard_data']['Pressure'], 'abs_pressure': station['dashboard_data']['AbsolutePressure'], 'pressurei': mBtoiHg(station['dashboard_data']['Pressure']), 'abs_pressurei': mBtoiHg(station['dashboard_data']['AbsolutePressure']), # noqa 'co2': int(station['dashboard_data']['CO2']), 'humidity': int(station['dashboard_data']['Humidity']), 'noise': int(station['dashboard_data']['Noise']), 'temp': station['dashboard_data']['Temperature'], 'max_temp': station['dashboard_data']['max_temp'], 'min_temp': station['dashboard_data']['min_temp'], 'tempf': CtoF(station['dashboard_data']['Temperature']), 'max_tempf': CtoF(station['dashboard_data']['max_temp']), 'min_tempf': CtoF(station['dashboard_data']['min_temp']), 'date_max_temp': epoch2date(station['dashboard_data']['date_max_temp']), 'date_min_temp': epoch2date(station['dashboard_data']['date_min_temp']), } } ]