constructor()

in src/device.ts [98:132]


  constructor(jsonData?: any) {
    this.deviceId = null;
    this.generationId = null;
    this.etag = null;
    this.connectionState = 'disconnected';
    this.status = 'enabled';
    this.statusReason = null;
    this.connectionStateUpdatedTime = null;
    this.statusUpdatedTime = null;
    this.lastActivityTime = null;
    this.cloudToDeviceMessageCount = '0';
    this.capabilities = {};
    this.authentication = {
      symmetricKey: {  // <- this is the correct thing (camel-cased)
        primaryKey: null,
        secondaryKey: null
      },
      x509Thumbprint: {
        primaryThumbprint: null,
        secondaryThumbprint: null
      }
    };

    /*Codes_SRS_NODE_SERVICE_DEVICE_16_002: [If the `deviceDescription` argument is provided as a string, it shall be parsed as JSON and the properties of the new `Device` object shall be populated with the values provided in the `deviceDescription` JSON string.]*/
    /*Codes_SRS_NODE_SERVICE_DEVICE_16_003: [If the `deviceDescription` argument if provided as an object, the properties of the new `Device` object shall be populated with the values provided in the `deviceDescription` JSON string.]*/
    if (jsonData) {
      const userProps = (typeof jsonData === 'string') ? JSON.parse(jsonData) : jsonData;
      if (!userProps.deviceId) {
        /*Codes_SRS_NODE_SERVICE_DEVICE_16_004: [The constructor shall throw a `ReferenceError` if the `deviceDescription` argument doesn't contain a `deviceId` property.]*/
        throw new ReferenceError('The \'deviceId\' property cannot be \'' + userProps.deviceId + '\'');
      }

      _.merge(this, userProps);
    }
  }