Home Reference Source

src/tangojs/core/api/AttributeProxy.js

  1.  
  2. import { DeviceProxy } from './DeviceProxy'
  3. import { DeviceAttribute } from './DeviceAttribute'
  4.  
  5. /** @private */
  6. const _proxy = Symbol.for('_proxy')
  7.  
  8. /** @private */
  9. const _attname = Symbol.for('_attname')
  10.  
  11. export class AttributeProxy {
  12.  
  13. /**
  14. * @param {string} devname
  15. * @param {string} attname
  16. */
  17. constructor (devname, attname) {
  18.  
  19. /** @private */
  20. this[_attname] = attname
  21.  
  22. /** @private */
  23. this[_proxy] = new DeviceProxy(devname)
  24. }
  25.  
  26. /**
  27. * @return {Promise<AttributeInfo,Error>}
  28. */
  29. get_info () {
  30. return this[_proxy].get_attribute_info(this[_attname])
  31. }
  32.  
  33. /**
  34. * @return {Promise<DeviceAttribute,Error>}
  35. */
  36. read () {
  37. return this[_proxy].read_attribute(this[_attname])
  38. }
  39.  
  40. /**
  41. * @param {DeviceAttribute} attr
  42. * @return {Promise<undefined,Error>}
  43. */
  44. write (attr) {
  45. // FIXME do sth with accessing private _data
  46. const data = Object.assign({}, attr._data, { name: this[_attname] })
  47. const attribute = new DeviceAttribute(data)
  48. return this[_proxy].write_attribute(attribute)
  49. }
  50. }