From 33348c4f429574b74a42af77e7efc41d4f32873f Mon Sep 17 00:00:00 2001 From: Holger Eisold Date: Mon, 28 Oct 2019 03:59:25 +0100 Subject: [PATCH 1/4] Updated pet photo channel to get updated if photo was deleted. Signed-off-by: Holger Eisold --- .../binding/surepetcare/internal/SurePetcareAPIHelper.java | 2 +- .../surepetcare/internal/handler/SurePetcarePetHandler.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareAPIHelper.java b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareAPIHelper.java index 134ec20c05283..03e2e4f991847 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareAPIHelper.java +++ b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareAPIHelper.java @@ -69,7 +69,7 @@ public class SurePetcareAPIHelper { private static final String API_URL = "https://app.api.surehub.io/api"; private static final String TOPOLOGY_URL = API_URL + "/me/start"; private static final String PET_BASE_URL = API_URL + "/pet"; - private static final String PET_STATUS_URL = API_URL + "/pet/?with[]=status"; + private static final String PET_STATUS_URL = API_URL + "/pet/?with[]=status&with[]=photo"; private static final String DEVICE_BASE_URL = API_URL + "/device"; private static final String LOGIN_URL = API_URL + "/auth/login"; diff --git a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java index 0f047547014fa..c4b4ae4af4679 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java +++ b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java @@ -30,6 +30,7 @@ import org.eclipse.smarthome.core.thing.Thing; import org.eclipse.smarthome.core.types.Command; import org.eclipse.smarthome.core.types.RefreshType; +import org.eclipse.smarthome.core.types.UnDefType; import org.eclipse.smarthome.io.net.http.HttpUtil; import org.openhab.binding.surepetcare.internal.SurePetcareAPIHelper; import org.openhab.binding.surepetcare.internal.SurePetcareApiException; @@ -123,9 +124,8 @@ protected void updateThing() { if (pet.getSpeciesId() != null) { updateState(PET_CHANNEL_SPECIES, new StringType(pet.getSpeciesId().toString())); } - if (pet.getPhoto() != null) { - updateState(PET_CHANNEL_PHOTO, getPetPhotoImage(pet.getPhoto().getLocation())); - } + updateState(PET_CHANNEL_PHOTO, + pet.getPhoto() == null ? UnDefType.UNDEF : getPetPhotoImage(pet.getPhoto().getLocation())); SurePetcarePetActivity loc = pet.getPetStatus().getActivity(); if (loc != null) { updateState(PET_CHANNEL_LOCATION, new StringType(loc.getWhere().toString())); From 65801d706ff2a08f0c2845bbf7bfdfd64eb1aba4 Mon Sep 17 00:00:00 2001 From: Holger Eisold Date: Mon, 28 Oct 2019 04:35:58 +0100 Subject: [PATCH 2/4] Use Thing property constants and cleanup for removed channels Signed-off-by: Holger Eisold --- .../internal/SurePetcareConstants.java | 10 -- .../internal/data/SurePetcareBaseObject.java | 10 -- .../internal/data/SurePetcareDevice.java | 15 +-- .../data/SurePetcareDeviceStatus.java | 6 +- .../handler/SurePetcareHouseholdHandler.java | 3 - .../ESH-INF/i18n/surepetcare.properties | 21 ---- .../ESH-INF/i18n/surepetcare_de.properties | 21 ---- .../main/resources/ESH-INF/thing/things.xml | 112 ++++-------------- .../internal/data/SurePetcareDeviceTest.java | 5 +- 9 files changed, 33 insertions(+), 170 deletions(-) diff --git a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareConstants.java b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareConstants.java index 9d615574f4d5f..e122b02ce50e4 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareConstants.java +++ b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareConstants.java @@ -61,9 +61,6 @@ public class SurePetcareConstants { public static final String HOUSEHOLD_CHANNEL_ID = "id"; public static final String HOUSEHOLD_CHANNEL_NAME = "name"; public static final String HOUSEHOLD_CHANNEL_TIMEZONE_ID = "timezoneId"; - public static final String HOUSEHOLD_CHANNEL_CREATED_AT = "createdAt"; - public static final String HOUSEHOLD_CHANNEL_UPDATED_AT = "updatedAt"; - public static final String HOUSEHOLD_CHANNEL_USER_NAME = "userName"; // Device Channel Names public static final String DEVICE_CHANNEL_ID = "id"; @@ -71,8 +68,6 @@ public class SurePetcareConstants { public static final String DEVICE_CHANNEL_PRODUCT = "product"; public static final String DEVICE_CHANNEL_LED_MODE = "ledMode"; public static final String DEVICE_CHANNEL_PAIRING_MODE = "pairingMode"; - public static final String DEVICE_CHANNEL_HARDWARE_VERSION = "hardwareVersion"; - public static final String DEVICE_CHANNEL_FIRMWARE_VERSION = "firmwareVersion"; public static final String DEVICE_CHANNEL_ONLINE = "online"; public static final String DEVICE_CHANNEL_CURFEW_BASE = "curfew"; public static final String DEVICE_CHANNEL_CURFEW_ENABLED = DEVICE_CHANNEL_CURFEW_BASE + "Enabled"; @@ -84,11 +79,6 @@ public class SurePetcareConstants { public static final String DEVICE_CHANNEL_LOW_BATTERY = "lowBattery"; public static final String DEVICE_CHANNEL_DEVICE_RSSI = "deviceRSSI"; public static final String DEVICE_CHANNEL_HUB_RSSI = "hubRSSI"; - public static final String DEVICE_CHANNEL_CREATED_AT = "createdAt"; - public static final String DEVICE_CHANNEL_UPDATED_AT = "updatedAt"; - public static final String DEVICE_CHANNEL_PAIRING_AT = "pairingAt"; - public static final String DEVICE_CHANNEL_SERIAL_NUMBER = "serialNumber"; - public static final String DEVICE_CHANNEL_MAC_ADDRESS = "macAddress"; public static final String DEVICE_CHANNEL_BOWLS_FOOD = "bowlsFood"; public static final String DEVICE_CHANNEL_BOWLS_TARGET = "bowlsTarget"; public static final String DEVICE_CHANNEL_BOWLS_FOOD_LEFT = "bowlsFoodLeft"; diff --git a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareBaseObject.java b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareBaseObject.java index c02f38af33730..7303bee4a85c3 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareBaseObject.java +++ b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareBaseObject.java @@ -12,8 +12,6 @@ */ package org.openhab.binding.surepetcare.internal.data; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -69,14 +67,6 @@ public void setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; } - public ZonedDateTime getCreatedAtAsZonedDateTime() { - return createdAt.toInstant().atZone(ZoneId.systemDefault()); - } - - public ZonedDateTime getUpdatedAtAsZonedDateTime() { - return updatedAt.toInstant().atZone(ZoneId.systemDefault()); - } - public Map getThingProperties() { Map properties = new HashMap(); properties.put("id", id.toString()); diff --git a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDevice.java b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDevice.java index 1d2d36fff80f4..df6f533ffc32f 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDevice.java +++ b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDevice.java @@ -12,13 +12,12 @@ */ package org.openhab.binding.surepetcare.internal.data; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.util.Arrays; import java.util.Date; import java.util.Map; import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.smarthome.core.thing.Thing; /** * The {@link SurePetcareDevice} is the Java class used @@ -163,10 +162,10 @@ public void setStatus(SurePetcareDeviceStatus status) { properties.put("householdId", householdId.toString()); properties.put("productType", productId.toString()); properties.put("productName", ProductType.findByTypeId(productId).getName()); - properties.put("macAddress", macAddress); - properties.put("serialNumber", serialNumber); - properties.put("hardwareVersion", status.getVersion().device.hardware.toString()); - properties.put("firmwareVersion", status.getVersion().device.firmware.toString()); + properties.put(Thing.PROPERTY_MAC_ADDRESS, macAddress); + properties.put(Thing.PROPERTY_SERIAL_NUMBER, serialNumber); + properties.put(Thing.PROPERTY_HARDWARE_VERSION, status.getVersion().device.hardware); + properties.put(Thing.PROPERTY_FIRMWARE_VERSION, status.getVersion().device.firmware); if (pairingAt != null) { properties.put("pairingAt", pairingAt.toString()); } @@ -179,10 +178,6 @@ public String toString() { + "]"; } - public @NonNull ZonedDateTime getPairingAtAsZonedDateTime() { - return pairingAt.toInstant().atZone(ZoneId.systemDefault()); - } - public SurePetcareDevice assign(SurePetcareDevice newdev) { super.assign(newdev); this.parentDeviceId = newdev.parentDeviceId; diff --git a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDeviceStatus.java b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDeviceStatus.java index b2b51d80a8e3c..0636877cbb10b 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDeviceStatus.java +++ b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDeviceStatus.java @@ -12,8 +12,6 @@ */ package org.openhab.binding.surepetcare.internal.data; -import java.math.BigDecimal; - import com.google.gson.annotations.SerializedName; /** @@ -31,8 +29,8 @@ public class Locking { public class Version { public class Device { - public BigDecimal hardware; - public BigDecimal firmware; + public String hardware; + public String firmware; } public Device device = new Device(); diff --git a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcareHouseholdHandler.java b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcareHouseholdHandler.java index 895ebfb1cec42..bbb84201f0d62 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcareHouseholdHandler.java +++ b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcareHouseholdHandler.java @@ -15,7 +15,6 @@ import static org.openhab.binding.surepetcare.internal.SurePetcareConstants.*; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.eclipse.smarthome.core.library.types.DateTimeType; import org.eclipse.smarthome.core.library.types.DecimalType; import org.eclipse.smarthome.core.library.types.StringType; import org.eclipse.smarthome.core.thing.Thing; @@ -47,8 +46,6 @@ protected void updateThing() { updateState(HOUSEHOLD_CHANNEL_ID, new DecimalType(household.getId())); updateState(HOUSEHOLD_CHANNEL_NAME, new StringType(household.getName())); updateState(HOUSEHOLD_CHANNEL_TIMEZONE_ID, new DecimalType(household.getTimezoneId())); - updateState(HOUSEHOLD_CHANNEL_CREATED_AT, new DateTimeType(household.getCreatedAtAsZonedDateTime())); - updateState(HOUSEHOLD_CHANNEL_UPDATED_AT, new DateTimeType(household.getUpdatedAtAsZonedDateTime())); } else { logger.debug("Trying to update unknown household: {}", thing.getUID().getId()); } diff --git a/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/i18n/surepetcare.properties b/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/i18n/surepetcare.properties index 91231365c78ed..41ba3915aaf27 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/i18n/surepetcare.properties +++ b/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/i18n/surepetcare.properties @@ -156,12 +156,6 @@ channel-type.surepetcare.pairingModeType.description = The current pairing mode channel-type.surepetcare.pairingModeType.state.option.0 = Normal Mode channel-type.surepetcare.pairingModeType.state.option.1 = Pairing Mode -channel-type.surepetcare.hardwareVersionType.label = Hardware Version -channel-type.surepetcare.hardwareVersionType.description = The version of the hardware. - -channel-type.surepetcare.firmwareVersionType.label = Firmware Version -channel-type.surepetcare.firmwareVersionType.description = The version of the firmware. - channel-type.surepetcare.onlineType.label = Online State channel-type.surepetcare.onlineType.description = Indicator if device is online or offline. @@ -174,21 +168,6 @@ channel-type.surepetcare.curfewLockTimeType.description = The time when the curf channel-type.surepetcare.curfewUnlockTimeType.label = Curfew Unlock Time channel-type.surepetcare.curfewUnlockTimeType.description = The time when the curfew finishes. -channel-type.surepetcare.createdAtType.label = Created At -channel-type.surepetcare.createdAtType.description = The Time when the device was created. - -channel-type.surepetcare.updatedAtType.label = Updated At -channel-type.surepetcare.updatedAtType.description = The Time when the device was updated. - -channel-type.surepetcare.pairingAtType.label = Pairing At -channel-type.surepetcare.pairingAtType.description = The Time when the device was paired. - -channel-type.surepetcare.serialNumberType.label = Serial Number -channel-type.surepetcare.serialNumberType.description = The serial number of the device. - -channel-type.surepetcare.macAddressType.label = MAC Address -channel-type.surepetcare.macAddressType.description = The MAC address of the device. - channel-type.surepetcare.dateOfBirthType.label = Pet Birthday channel-type.surepetcare.dateOfBirthType.description = The pet birthday. diff --git a/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/i18n/surepetcare_de.properties b/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/i18n/surepetcare_de.properties index 71d9e6618017a..6133f0b0b584a 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/i18n/surepetcare_de.properties +++ b/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/i18n/surepetcare_de.properties @@ -156,12 +156,6 @@ channel-type.surepetcare.pairingModeType.description = Zeigt den Paarungs Modus channel-type.surepetcare.pairingModeType.state.option.0 = Normaler Modus channel-type.surepetcare.pairingModeType.state.option.1 = Paarungsmodus -channel-type.surepetcare.hardwareVersionType.label = Hardware Version -channel-type.surepetcare.hardwareVersionType.description = Zeigt die Hardware Version des Gerätes an. - -channel-type.surepetcare.firmwareVersionType.label = Firmware Version -channel-type.surepetcare.firmwareVersionType.description = Zeigt die Firmware Version des Gerätes an. - channel-type.surepetcare.onlineType.label = Online Status channel-type.surepetcare.onlineType.description = Zeigt den Online Status des Gerätes an. @@ -174,21 +168,6 @@ channel-type.surepetcare.curfewLockTimeType.description = Zeigt die Sperrzeit de channel-type.surepetcare.curfewUnlockTimeType.label = Ausgangssperre Entsperrzeit channel-type.surepetcare.curfewUnlockTimeType.description = Zeigt die Entsperrzeit der Ausgangssperre an. -channel-type.surepetcare.createdAtType.label = Erstell Datum -channel-type.surepetcare.createdAtType.description = Zeigt das Erstelldatum an. - -channel-type.surepetcare.updatedAtType.label = Aktualisierungs Datum -channel-type.surepetcare.updatedAtType.description = Zeigt das Aktualisierungsdatum an. - -channel-type.surepetcare.pairingAtType.label = Verbindungs Datum -channel-type.surepetcare.pairingAtType.description = Zeigt das Verbindungsdatum an. - -channel-type.surepetcare.serialNumberType.label = Serien Nummer -channel-type.surepetcare.serialNumberType.description = Zeigt die Seriennummer des Gerätes an. - -channel-type.surepetcare.macAddressType.label = MAC Adresse -channel-type.surepetcare.macAddressType.description = Zeigt die MAC Adresse des Gerätes an. - channel-type.surepetcare.dateOfBirthType.label = Geburtstag channel-type.surepetcare.dateOfBirthType.description = Zeigt den Geburtstag des Haus an. diff --git a/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/thing/things.xml b/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/thing/things.xml index bc1f66d7fd268..ba643b36fff61 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/thing/things.xml +++ b/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/thing/things.xml @@ -1,9 +1,6 @@ - + @@ -49,16 +46,12 @@ - - - - - - - - - - + + + + + + @@ -95,18 +88,15 @@ + - - - - - - - - + + + + @@ -139,19 +129,16 @@ + - - - - - - - - - - - - + + + + + + + + @@ -183,12 +170,13 @@ + - + @@ -333,7 +321,7 @@ Image - The URL of the pet photo + The image of the pet @@ -395,20 +383,6 @@ - - Number - - The version of the hardware - - - - - Number - - The version of the firmware - - - Switch @@ -437,44 +411,6 @@ - - DateTime - - The Time when the device was created. - Time - - - - - DateTime - - The Time when the device was updated. - Time - - - - - DateTime - - The Time when the device was paired. - Time - - - - - String - - The serial number of the device. - - - - - String - - The MAC address of the device. - - - DateTime diff --git a/bundles/org.openhab.binding.surepetcare/src/test/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDeviceTest.java b/bundles/org.openhab.binding.surepetcare/src/test/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDeviceTest.java index aebe091f53359..f2d05940f6bfb 100644 --- a/bundles/org.openhab.binding.surepetcare/src/test/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDeviceTest.java +++ b/bundles/org.openhab.binding.surepetcare/src/test/java/org/openhab/binding/surepetcare/internal/data/SurePetcareDeviceTest.java @@ -14,7 +14,6 @@ import static org.junit.Assert.assertEquals; -import java.math.BigDecimal; import java.text.ParseException; import org.junit.Test; @@ -43,8 +42,8 @@ public void testJsonDeserializeHub() throws ParseException { assertEquals(new Integer(0), response.getControl().getPairingModeId()); assertEquals(new Integer(4), response.getStatus().getLedModeId()); assertEquals(new Integer(0), response.getStatus().getPairingModeId()); - assertEquals(new BigDecimal("3"), response.getStatus().getVersion().device.hardware); - assertEquals(new BigDecimal("1.772"), response.getStatus().getVersion().device.firmware); + assertEquals("3", response.getStatus().getVersion().device.hardware); + assertEquals("1.772", response.getStatus().getVersion().device.firmware); } @Test From 716101d50a95897630215955fd3eb6c980fab8a5 Mon Sep 17 00:00:00 2001 From: Holger Eisold Date: Mon, 28 Oct 2019 04:43:56 +0100 Subject: [PATCH 3/4] Updated pet channels so we receive updates if user set something to null Signed-off-by: Holger Eisold --- .../handler/SurePetcarePetHandler.java | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java index c4b4ae4af4679..c92c10cec9169 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java +++ b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java @@ -109,21 +109,15 @@ protected void updateThing() { if (pet != null) { logger.debug("Updating all thing channels for pet : {}", pet); updateState(PET_CHANNEL_ID, new DecimalType(pet.getId())); - if (pet.getName() != null) { - updateState(PET_CHANNEL_NAME, new StringType(pet.getName())); - } - if (pet.getComments() != null) { - updateState(PET_CHANNEL_COMMENT, new StringType(pet.getComments())); - } - if (pet.getGenderId() != null) { - updateState(PET_CHANNEL_GENDER, new StringType(pet.getGenderId().toString())); - } - if (pet.getBreedId() != null) { - updateState(PET_CHANNEL_BREED, new StringType(pet.getBreedId().toString())); - } - if (pet.getSpeciesId() != null) { - updateState(PET_CHANNEL_SPECIES, new StringType(pet.getSpeciesId().toString())); - } + updateState(PET_CHANNEL_NAME, pet.getName() == null ? UnDefType.UNDEF : new StringType(pet.getName())); + updateState(PET_CHANNEL_COMMENT, + pet.getComments() == null ? UnDefType.UNDEF : new StringType(pet.getComments())); + updateState(PET_CHANNEL_GENDER, + pet.getGenderId() == null ? UnDefType.UNDEF : new StringType(pet.getGenderId().toString())); + updateState(PET_CHANNEL_BREED, + pet.getBreedId() == null ? UnDefType.UNDEF : new StringType(pet.getBreedId().toString())); + updateState(PET_CHANNEL_SPECIES, + pet.getSpeciesId() == null ? UnDefType.UNDEF : new StringType(pet.getSpeciesId().toString())); updateState(PET_CHANNEL_PHOTO, pet.getPhoto() == null ? UnDefType.UNDEF : getPetPhotoImage(pet.getPhoto().getLocation())); SurePetcarePetActivity loc = pet.getPetStatus().getActivity(); @@ -134,12 +128,9 @@ protected void updateThing() { } } ZonedDateTime dob = pet.getDateOfBirthAsZonedDateTime(); - if (dob != null) { - updateState(PET_CHANNEL_DATE_OF_BIRTH, new DateTimeType(dob)); - } - if (pet.getWeight() != null) { - updateState(PET_CHANNEL_WEIGHT, new DecimalType(pet.getWeight())); - } + updateState(PET_CHANNEL_DATE_OF_BIRTH, dob == null ? UnDefType.UNDEF : new DateTimeType(dob)); + updateState(PET_CHANNEL_WEIGHT, + pet.getWeight() == null ? UnDefType.UNDEF : new DecimalType(pet.getWeight())); if (pet.getTagId() != null) { SurePetcareTag tag = petcareAPI.getTag(pet.getTagId().toString()); if (tag != null) { From b2dd94ef67ce1472f586a0397bb8bbfa66d762d7 Mon Sep 17 00:00:00 2001 From: Holger Eisold Date: Mon, 28 Oct 2019 04:53:40 +0100 Subject: [PATCH 4/4] Changed pet weigh to Number:Mass kilogram Signed-off-by: Holger Eisold --- bundles/org.openhab.binding.surepetcare/README.md | 4 ++-- .../org.openhab.binding.surepetcare/config/items/pet.items | 2 +- .../surepetcare/internal/handler/SurePetcarePetHandler.java | 4 ++-- .../src/main/resources/ESH-INF/thing/things.xml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.surepetcare/README.md b/bundles/org.openhab.binding.surepetcare/README.md index 3a98d9ca89420..ad5d06c1c8fc0 100644 --- a/bundles/org.openhab.binding.surepetcare/README.md +++ b/bundles/org.openhab.binding.surepetcare/README.md @@ -162,7 +162,7 @@ Channel names in **bold** are read/write, everything else is read-only | **location** | Text | The current location of the pet (0=unknown, 1=inside, 2=outside) | | locationChanged | DateTime | The time when the location was last changed | | locationChangedThrough | Text | The device name or username where the pet left/entered the house | -| weight | Number | The pet's weight | +| weight | Number:Mass | The pet's weight (in kilogram) | | dateOfBirth | DateTime | The pet's date of birth | | feederDevice | Text | The device from which the pet last ate | | feederLastChange | Number:Mass | The last eaten change in gram (big bowl) | @@ -270,7 +270,7 @@ String UR_1e_TagIdentifier "Pet Tag Identifier [%s]" (dgP String UR_1e_Location "Pet Location [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:location"} DateTime UR_1e_LocationChanged "Pet Loc. Updated [%1$ta. %1$tH:%1$tM]" (dgPet) {channel="surepetcare:pet:bridge1:12345:locationChanged"} String UR_1e_LocationThrough "Pet Entered / Left through [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:locationChangedThrough"} -Number UR_1e_Weight "Pet Weight [%.1f kg]" (dgPet) {channel="surepetcare:pet:bridge1:12345:weight"} +Number:Mass UR_1e_Weight "Pet Weight [%.1f %unit%]" (dgPet) {channel="surepetcare:pet:bridge1:12345:weight"} DateTime UR_1e_DateOfBirth "Pet Date of Birth [%1$td.%1$tm.%1$tY]" (dgPet) {channel="surepetcare:pet:bridge1:12345:dateOfBirth"} // Pet Feeder Data String UR_1e_Device "Device Name [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:feederDevice"} diff --git a/bundles/org.openhab.binding.surepetcare/config/items/pet.items b/bundles/org.openhab.binding.surepetcare/config/items/pet.items index cccd49fa8f13b..e6793911a5606 100644 --- a/bundles/org.openhab.binding.surepetcare/config/items/pet.items +++ b/bundles/org.openhab.binding.surepetcare/config/items/pet.items @@ -9,7 +9,7 @@ String UR_1e_TagIdentifier "Pet Tag Identifier [%s]" (dgP String UR_1e_Location "Pet Location [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:location"} DateTime UR_1e_LocationChanged "Pet Loc. Updated [%1$ta. %1$tH:%1$tM]" (dgPet) {channel="surepetcare:pet:bridge1:12345:locationChanged"} String UR_1e_LocationThrough "Pet Entered / Left through [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:locationChangedThrough"} -Number UR_1e_Weight "Pet Weight [%.1f kg]" (dgPet) {channel="surepetcare:pet:bridge1:12345:weight"} +Number:Mass UR_1e_Weight "Pet Weight [%.1f %unit%]" (dgPet) {channel="surepetcare:pet:bridge1:12345:weight"} DateTime UR_1e_DateOfBirth "Pet Date of Birth [%1$td.%1$tm.%1$tY]" (dgPet) {channel="surepetcare:pet:bridge1:12345:dateOfBirth"} // Pet Feeder Data String UR_1e_Device "Device Name [%s]" (dgPet) {channel="surepetcare:pet:bridge1:12345:feederDevice"} diff --git a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java index c92c10cec9169..ae75451c6eccc 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java +++ b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/handler/SurePetcarePetHandler.java @@ -129,8 +129,8 @@ protected void updateThing() { } ZonedDateTime dob = pet.getDateOfBirthAsZonedDateTime(); updateState(PET_CHANNEL_DATE_OF_BIRTH, dob == null ? UnDefType.UNDEF : new DateTimeType(dob)); - updateState(PET_CHANNEL_WEIGHT, - pet.getWeight() == null ? UnDefType.UNDEF : new DecimalType(pet.getWeight())); + updateState(PET_CHANNEL_WEIGHT, pet.getWeight() == null ? UnDefType.UNDEF + : new QuantityType(pet.getWeight(), SIUnits.KILOGRAM)); if (pet.getTagId() != null) { SurePetcareTag tag = petcareAPI.getTag(pet.getTagId().toString()); if (tag != null) { diff --git a/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/thing/things.xml b/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/thing/things.xml index ba643b36fff61..f86d970bac065 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/thing/things.xml +++ b/bundles/org.openhab.binding.surepetcare/src/main/resources/ESH-INF/thing/things.xml @@ -420,10 +420,10 @@ - Number + Number:Mass The pet weight - +