@Component(service = GreeDeviceFinder.class, configurationPid = "devicefinder.gree")
public class GreeDeviceFinder {
private final Logger logger = LoggerFactory.getLogger(GreeDeviceFinder.class);
- private static final Gson gson = (new GsonBuilder()).create();
+ private static final Gson GSON = (new GsonBuilder()).create();
protected final InetAddress ipAddress = InetAddress.getLoopbackAddress();
protected Map<String, GreeAirDevice> deviceTable = new HashMap<>();
// Send the Scan message
GreeScanRequestDTO scanGson = new GreeScanRequestDTO();
scanGson.t = GREE_CMDT_SCAN;
- String scanReq = gson.toJson(scanGson);
+ String scanReq = GSON.toJson(scanGson);
sendData = scanReq.getBytes(StandardCharsets.UTF_8);
logger.debug("Sending scan packet to {}", ipAddress.getHostAddress());
clientSocket.setSoTimeout(DISCOVERY_TIMEOUT_MS);
logger.debug("Response received from address {}: {}", remoteAddress.getHostAddress(), decryptedMsg);
// Create the JSON to hold the response values
- scanResponseGson.packJson = gson.fromJson(decryptedMsg, GreeScanReponsePackDTO.class);
+ scanResponseGson.packJson = GSON.fromJson(decryptedMsg, GreeScanReponsePackDTO.class);
// Now make sure the device is reported as a Gree device
if (scanResponseGson.packJson.brand.equalsIgnoreCase("gree")) {
private <T> T fromJson(DatagramPacket packet, Class<T> classOfT) {
String json = new String(packet.getData(), StandardCharsets.UTF_8).replace("\\u0000", "").trim();
- return gson.fromJson(json, classOfT);
+ return GSON.fromJson(json, classOfT);
}
public void addDevice(GreeAirDevice newDevice) {
@NonNullByDefault
public class GreeAirDevice {
private final Logger logger = LoggerFactory.getLogger(GreeAirDevice.class);
- private static final Gson gson = new Gson();
+ private static final Gson GSON = new Gson();
private boolean isBound = false;
private final InetAddress ipAddress;
private int port = 0;
reqStatusPackGson.t = GREE_CMDT_STATUS;
reqStatusPackGson.cols = colArray;
reqStatusPackGson.mac = getId();
- String reqStatusPackStr = gson.toJson(reqStatusPackGson);
+ String reqStatusPackStr = GSON.toJson(reqStatusPackGson);
// Encrypt and send the Status Request pack
String encryptedStatusReqPacket = GreeCryptoUtil.encryptPack(getKey(), reqStatusPackStr);
GreeStatusResponseDTO resp = receiveResponse(clientSocket, GreeStatusResponseDTO.class);
resp.decryptedPack = GreeCryptoUtil.decryptPack(getKey(), resp.pack);
logger.debug("Response from device: {}", resp.decryptedPack);
- resp.packJson = gson.fromJson(resp.decryptedPack, GreeStatusResponsePackDTO.class);
+ resp.packJson = GSON.fromJson(resp.decryptedPack, GreeStatusResponsePackDTO.class);
// save the results
statusResponseGson = Optional.of(resp);
bindReqPackGson.mac = getId();
bindReqPackGson.t = GREE_CMDT_BIND;
bindReqPackGson.uid = 0;
- String bindReqPackStr = gson.toJson(bindReqPackGson);
+ String bindReqPackStr = GSON.toJson(bindReqPackGson);
// Encrypt and send the Binding Request pack
String encryptedBindReqPacket = GreeCryptoUtil.encryptPack(GreeCryptoUtil.getAESGeneralKeyByteArray(),
// Recieve a response, create the JSON to hold the response values
GreeBindResponseDTO resp = receiveResponse(clientSocket, GreeBindResponseDTO.class);
resp.decryptedPack = GreeCryptoUtil.decryptPack(GreeCryptoUtil.getAESGeneralKeyByteArray(), resp.pack);
- resp.packJson = gson.fromJson(resp.decryptedPack, GreeBindResponsePackDTO.class);
+ resp.packJson = GSON.fromJson(resp.decryptedPack, GreeBindResponsePackDTO.class);
// Now set the key and flag to indicate the bind was successful
encKey = resp.packJson.key;
// If commanding Fahrenheit set halfStep to 1 or 0 to tell the A/C which F integer
// temperature to use as celsius alone is ambigious
double newVal = temp.doubleValue();
- int CorF = SIUnits.CELSIUS.equals(temp.getUnit()) ? TEMP_UNIT_CELSIUS : TEMP_UNIT_FAHRENHEIT; // 0=Celsius,
+ int celsiusOrFahrenheit = SIUnits.CELSIUS.equals(temp.getUnit()) ? TEMP_UNIT_CELSIUS : TEMP_UNIT_FAHRENHEIT; // 0=Celsius,
// 1=Fahrenheit
- if (((CorF == TEMP_UNIT_CELSIUS) && (newVal < TEMP_MIN_C || newVal > TEMP_MAX_C))
- || ((CorF == TEMP_UNIT_FAHRENHEIT) && (newVal < TEMP_MIN_F || newVal > TEMP_MAX_F))) {
+ if (((celsiusOrFahrenheit == TEMP_UNIT_CELSIUS) && (newVal < TEMP_MIN_C || newVal > TEMP_MAX_C))
+ || ((celsiusOrFahrenheit == TEMP_UNIT_FAHRENHEIT) && (newVal < TEMP_MIN_F || newVal > TEMP_MAX_F))) {
throw new IllegalArgumentException("Temp Value out of Range");
}
// ******************TempRec TemSet Mapping for setting Fahrenheit****************************
// subtract the float version - the int version to get the fractional difference
// if the difference is positive set halfStep to 1, negative to 0
- if (CorF == TEMP_UNIT_FAHRENHEIT) { // If Fahrenheit,
+ if (celsiusOrFahrenheit == TEMP_UNIT_FAHRENHEIT) { // If Fahrenheit,
halfStep = newVal - outVal > 0 ? TEMP_HALFSTEP_YES : TEMP_HALFSTEP_NO;
}
logger.debug("Converted temp from {}{} to temp={}, halfStep={}, unit={})", newVal, temp.getUnit(), outVal,
- halfStep, CorF == TEMP_UNIT_CELSIUS ? "C" : "F");
+ halfStep, celsiusOrFahrenheit == TEMP_UNIT_CELSIUS ? "C" : "F");
// Set the values in the HashMap
HashMap<String, Integer> parameters = new HashMap<>();
- parameters.put(GREE_PROP_TEMPUNIT, CorF);
+ parameters.put(GREE_PROP_TEMPUNIT, celsiusOrFahrenheit);
parameters.put(GREE_PROP_SETTEMP, outVal);
parameters.put(GREE_PROP_TEMPREC, halfStep);
executeCommand(clientSocket, parameters);
execCmdPackGson.opt = keyArray;
execCmdPackGson.p = valueArray;
execCmdPackGson.t = GREE_CMDT_CMD;
- String execCmdPackStr = gson.toJson(execCmdPackGson);
+ String execCmdPackStr = GSON.toJson(execCmdPackGson);
// Now encrypt and send the Command Request pack
String encryptedCommandReqPacket = GreeCryptoUtil.encryptPack(getKey(), execCmdPackStr);
execResponseGson.decryptedPack = GreeCryptoUtil.decryptPack(getKey(), execResponseGson.pack);
// Create the JSON to hold the response values
- execResponseGson.packJson = gson.fromJson(execResponseGson.decryptedPack, GreeExecResponsePackDTO.class);
+ execResponseGson.packJson = GSON.fromJson(execResponseGson.decryptedPack, GreeExecResponsePackDTO.class);
} catch (IOException | JsonSyntaxException e) {
throw new GreeException("Exception on command execution", e);
}
request.uid = 0;
request.tcid = getId();
request.pack = pack;
- byte[] sendData = gson.toJson(request).getBytes(StandardCharsets.UTF_8);
+ byte[] sendData = GSON.toJson(request).getBytes(StandardCharsets.UTF_8);
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipAddress, port);
return sendPacket;
}
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
String json = new String(receivePacket.getData(), StandardCharsets.UTF_8).replace("\\u0000", "").trim();
- return gson.fromJson(json, classOfT);
+ return GSON.fromJson(json, classOfT);
}
private void updateTempFtoC() {
// Status message back from A/C always reports degrees C
// If using Fahrenheit, us SetTem, TemUn and TemRec to reconstruct the Fahrenheit temperature
// Get Celsius or Fahrenheit from status message
- int CorF = getIntStatusVal(GREE_PROP_TEMPUNIT);
+ int celsiusOrFahrenheit = getIntStatusVal(GREE_PROP_TEMPUNIT);
int newVal = getIntStatusVal(GREE_PROP_SETTEMP);
int halfStep = getIntStatusVal(GREE_PROP_TEMPREC);
- if ((CorF == -1) || (newVal == -1) || (halfStep == -1)) {
+ if ((celsiusOrFahrenheit == -1) || (newVal == -1) || (halfStep == -1)) {
throw new IllegalArgumentException("SetTem,TemUn or TemRec is invalid, not performing conversion");
- } else if (CorF == 1) { // convert SetTem to Fahrenheit
+ } else if (celsiusOrFahrenheit == 1) { // convert SetTem to Fahrenheit
// Find the valueName in the Returned Status object
String[] columns = statusResponseGson.get().packJson.cols;
Integer[] values = statusResponseGson.get().packJson.dat;