@Override public IDeviceAssignment updateDeviceAssignmentMetadata(String token, IMetadataProvider metadata) throws SiteWhereException { IDeviceAssignment updated = super.updateDeviceAssignmentMetadata(token, metadata); DeviceStateChangeCreateRequest state = new DeviceStateChangeCreateRequest(StateChangeCategory.Assignment, StateChangeType.Assignment_Updated, null, null); SiteWhere.getServer().getDeviceEventManagement(getTenant()).addDeviceStateChange(updated.getToken(), state); return updated; }
@Override public IDeviceAssignment createDeviceAssignment(IDeviceAssignmentCreateRequest request) throws SiteWhereException { IDeviceAssignment created = super.createDeviceAssignment(request); DeviceStateChangeCreateRequest state = new DeviceStateChangeCreateRequest(StateChangeCategory.Assignment, StateChangeType.Assignment_Created, null, null); SiteWhere.getServer().getDeviceEventManagement(getTenant()).addDeviceStateChange(created.getToken(), state); return created; }
@Override public IDeviceAssignment endDeviceAssignment(String token) throws SiteWhereException { IDeviceAssignment updated = super.endDeviceAssignment(token); DeviceStateChangeCreateRequest state = new DeviceStateChangeCreateRequest(StateChangeCategory.Assignment, StateChangeType.Assignment_Released, null, null); SiteWhere.getServer().getDeviceEventManagement(getTenant()).addDeviceStateChange(updated.getToken(), state); return updated; }
@Override public IDeviceAssignment updateDeviceAssignment(UUID id, IDeviceAssignmentCreateRequest request) throws SiteWhereException { IDeviceAssignment updated = super.updateDeviceAssignment(id, request); updateTenantAuthentication(); DeviceStateChangeCreateRequest state = new DeviceStateChangeCreateRequest(); state.setAttribute(IDeviceStateChangeCreateRequest.ATTRIBUTE_ASSIGNMENT); state.setType("update"); getDeviceEventManagement().addDeviceStateChanges(updated.getId(), state); return updated; }
@Override public IDeviceAssignment createDeviceAssignment(IDeviceAssignmentCreateRequest request) throws SiteWhereException { IDeviceAssignment created = super.createDeviceAssignment(request); updateTenantAuthentication(); DeviceStateChangeCreateRequest state = new DeviceStateChangeCreateRequest(); state.setAttribute(IDeviceStateChangeCreateRequest.ATTRIBUTE_ASSIGNMENT); state.setType("create"); getDeviceEventManagement().addDeviceStateChanges(created.getId(), state); return created; }
@Override public IDeviceAssignment endDeviceAssignment(UUID id) throws SiteWhereException { IDeviceAssignment updated = super.endDeviceAssignment(id); updateTenantAuthentication(); DeviceStateChangeCreateRequest state = new DeviceStateChangeCreateRequest(); state.setAttribute(IDeviceStateChangeCreateRequest.ATTRIBUTE_ASSIGNMENT); state.setType("end"); getDeviceEventManagement().addDeviceStateChanges(updated.getId(), state); return updated; }
DeviceStateChangeCreateRequest create = new DeviceStateChangeCreateRequest( StateChangeCategory.Presence, StateChangeType.Presence_Updated, PresenceState.PRESENT.name(), PresenceState.NOT_PRESENT.name());
/** * Convert device state change create request from GRPC to API. * * @param grpc * @return * @throws SiteWhereException */ public static DeviceStateChangeCreateRequest asApiDeviceStateChangeCreateRequest( GDeviceStateChangeCreateRequest grpc) throws SiteWhereException { DeviceStateChangeCreateRequest api = new DeviceStateChangeCreateRequest(); api.setAttribute(grpc.getAttribute()); api.setType(grpc.getType()); api.setPreviousState(grpc.hasPreviousState() ? grpc.getPreviousState().getValue() : null); api.setNewState(grpc.hasNewState() ? grpc.getNewState().getValue() : null); EventModelConverter.copyApiDeviceEventCreateRequest(grpc.getEvent(), api); return api; }
/** * Create state change event to indicate device not present. * * @param deviceState * @throws SiteWhereException */ protected boolean sendPresenceMissing(IDeviceState deviceState) { DeviceStateChangeCreateRequest create = new DeviceStateChangeCreateRequest(); create.setAttribute(IDeviceStateChangeCreateRequest.ATTRIBUTE_PRESENCE); create.setType("automated"); create.setPreviousState(PresenceState.PRESENT.name()); create.setNewState(PresenceState.NOT_PRESENT.name()); try { // Only send an event if the strategy permits it. if (getPresenceNotificationStrategy().shouldGenerateEvent(deviceState, create)) { IDeviceEventManagement eventManagement = new BlockingDeviceEventManagement( getDeviceEventManagementApiChannel()); eventManagement.addDeviceStateChanges(deviceState.getDeviceAssignmentId(), create); return true; } } catch (SiteWhereException e) { getLogger().error("Unable to create state change event for presence missing.", e); } return false; } }