function setState(newState) {
  let imagePrefix = 'night';
  let title = '';

  switch (newState) {
    case StateEnum.DISABLED:
      chrome.power.releaseKeepAwake();
      imagePrefix = 'night';
      title = chrome.i18n.getMessage('disabledTitle');
      break;
    case StateEnum.DISPLAY:
      chrome.power.requestKeepAwake('display');
      imagePrefix = 'day';
      title = chrome.i18n.getMessage('displayTitle');
      break;
    case StateEnum.SYSTEM:
      chrome.power.requestKeepAwake('system');
      imagePrefix = 'sunset';
      title = chrome.i18n.getMessage('systemTitle');
      break;
    default:
      throw 'Invalid state "' + newState + '"';
  }

  let items = {};
  items[STATE_KEY] = newState;
  chrome.storage.local.set(items);

  chrome.action.setIcon({
    path: {
      19: 'images/' + imagePrefix + '-19.png',
      38: 'images/' + imagePrefix + '-38.png'
    }
  });
  chrome.action.setTitle({ title: title });
}
Switches to a new state.
@param {string} newState New {StateEnum} to use.