import time

from influxdb import InfluxDBClient
from influxdb import SeriesHelper

from . import config

# expects Cozify devices type json data
def getMultisensorData(data):
    out = []
    for device in data:
        state=data[device]['state']
        devtype = state['type']

        if devtype == 'STATE_MULTI_SENSOR':
            name=data[device]['name']
            if 'lastSeen' in state:
                timestamp=state['lastSeen']
            else:
                # if no time of measurement is known we must make a reasonable assumption
                # Stored here in milliseconds, influxDB internally stores as nanoseconds
                timestamp = time.time() * 1000
            if 'temperature' in state:
                temperature=state['temperature']
            else:
                temperature=None
            if 'humidity' in state:
                humidity=state['humidity']
            else:
                humidity=None

            out.append({
                    'name': name,
                    'time': timestamp,
                    'temperature': temperature,
                    'humidity': humidity
                    })
    return out

import time

from influxdb import InfluxDBClient
from influxdb import SeriesHelper

from . import config

# expects Cozify devices type json data
def getMultisensorData(data):
    out = []
    for device in data:
        state=data[device]['state']
        devtype = state['type']

        if devtype == 'STATE_MULTI_SENSOR':
            name=data[device]['name']
            if 'lastSeen' in state:
                timestamp=state['lastSeen']
            else:
                # if no time of measurement is known we must make a reasonable assumption
                # Stored here in milliseconds to match accuracy of what the hub will give you
                timestamp = time.time() * 1000
            if 'temperature' in state:
                temperature=state['temperature']
            else:
                temperature=None
            if 'humidity' in state:
                humidity=state['humidity']
            else:
                humidity=None

            out.append({
                    'name': name,
                    'time': timestamp,
                    'temperature': temperature,
                    'humidity': humidity
                    })
    return out

Make comment about time accuracy more universal
Make comment about time accuracy more universal

  import time
  
  from influxdb import InfluxDBClient
  from influxdb import SeriesHelper
  
  from . import config
  
  # expects Cozify devices type json data
  def getMultisensorData(data):
      out = []
      for device in data:
          state=data[device]['state']
          devtype = state['type']
  
          if devtype == 'STATE_MULTI_SENSOR':
              name=data[device]['name']
              if 'lastSeen' in state:
                  timestamp=state['lastSeen']
              else:
                  # if no time of measurement is known we must make a reasonable assumption
-                 # Stored here in milliseconds, influxDB internally stores as nanoseconds
+                 # Stored here in milliseconds to match accuracy of what the hub will give you
                  timestamp = time.time() * 1000
              if 'temperature' in state:
                  temperature=state['temperature']
              else:
                  temperature=None
              if 'humidity' in state:
                  humidity=state['humidity']
              else:
                  humidity=None
  
              out.append({
                      'name': name,
                      'time': timestamp,
                      'temperature': temperature,
                      'humidity': humidity
                      })
      return out
  
Make comment about time accuracy more universal
## Code Before:
import time

from influxdb import InfluxDBClient
from influxdb import SeriesHelper

from . import config

# expects Cozify devices type json data
def getMultisensorData(data):
    out = []
    for device in data:
        state=data[device]['state']
        devtype = state['type']

        if devtype == 'STATE_MULTI_SENSOR':
            name=data[device]['name']
            if 'lastSeen' in state:
                timestamp=state['lastSeen']
            else:
                # if no time of measurement is known we must make a reasonable assumption
                # Stored here in milliseconds, influxDB internally stores as nanoseconds
                timestamp = time.time() * 1000
            if 'temperature' in state:
                temperature=state['temperature']
            else:
                temperature=None
            if 'humidity' in state:
                humidity=state['humidity']
            else:
                humidity=None

            out.append({
                    'name': name,
                    'time': timestamp,
                    'temperature': temperature,
                    'humidity': humidity
                    })
    return out

## Instruction:
Make comment about time accuracy more universal
## Code After:
import time

from influxdb import InfluxDBClient
from influxdb import SeriesHelper

from . import config

# expects Cozify devices type json data
def getMultisensorData(data):
    out = []
    for device in data:
        state=data[device]['state']
        devtype = state['type']

        if devtype == 'STATE_MULTI_SENSOR':
            name=data[device]['name']
            if 'lastSeen' in state:
                timestamp=state['lastSeen']
            else:
                # if no time of measurement is known we must make a reasonable assumption
                # Stored here in milliseconds to match accuracy of what the hub will give you
                timestamp = time.time() * 1000
            if 'temperature' in state:
                temperature=state['temperature']
            else:
                temperature=None
            if 'humidity' in state:
                humidity=state['humidity']
            else:
                humidity=None

            out.append({
                    'name': name,
                    'time': timestamp,
                    'temperature': temperature,
                    'humidity': humidity
                    })
    return out
