bryan-bartow / homebridge-alarm.com

Alarm.com plugin for Homebridge
ISC License
43 stars 11 forks source link

Reference latest versions of API calls as opposed to specific versions #41

Closed bryanbartow closed 6 years ago

bryanbartow commented 7 years ago

As mentioned here, the plugin should reference latest on all WrapAPI calls instead of a specific version of the app. For instance, this excerpt from the login call:

login() {
  if (!this.currentSession) {
    const session = this.send('initlogin/0.0.3').then(json => {
      const sessionUrl = json.data.sessionUrl;
      return this.send('login/0.1.1', {
        sessionUrl,
        username: this.config.username,
        password: this.config.password,
      }).then(json => {
        switch (json.data.alarmState) {
          case 'Disarmed':
            return Characteristic.SecuritySystemCurrentState.DISARMED;
          case 'Armed Stay':
            return Characteristic.SecuritySystemCurrentState.STAY_ARM;
          case 'Armed Away':
            return Characteristic.SecuritySystemCurrentState.AWAY_ARM;
          default:
            return null;
        }
    })

Should instead read:

login() {
  if (!this.currentSession) {
    const session = this.send('initlogin/latest').then(json => {
      const sessionUrl = json.data.sessionUrl;
      return this.send('login/latest', {
        sessionUrl,
        username: this.config.username,
        password: this.config.password,
      }).then(json => {
        switch (json.data.alarmState) {
          case 'Disarmed':
            return Characteristic.SecuritySystemCurrentState.DISARMED;
          case 'Armed Stay':
            return Characteristic.SecuritySystemCurrentState.STAY_ARM;
          case 'Armed Away':
            return Characteristic.SecuritySystemCurrentState.AWAY_ARM;
          default:
            return null;
        }
    })

This would allow changes to individual calls on WrapAPI to be made without necessitating an update to the plugin itself. Of course, if one of said changes were breaking, the plugin would have to be updated. Those changes should be the exception rather than the rule, however.

jdshkolnik commented 6 years ago

I think this makes sense to do. Easier to centrally correct the latest API than to require everyone update their plugins.

jdshkolnik commented 6 years ago

This has been merged in PR #68 and will appear in the next release.