]> git.basschouten.com Git - openhab-addons.git/blob
76d750f040aa15b6b0a4d1463b95f84fa92aa409
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.surepetcare.internal.handler;
14
15 import static org.openhab.binding.surepetcare.internal.SurePetcareConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.surepetcare.internal.SurePetcareAPIHelper;
19 import org.openhab.binding.surepetcare.internal.dto.SurePetcareHousehold;
20 import org.openhab.core.library.types.DecimalType;
21 import org.openhab.core.library.types.StringType;
22 import org.openhab.core.thing.Thing;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 /**
27  * The {@link SurePetcareHouseholdHandler} is responsible for handling things created to represent Sure Petcare
28  * households.
29  *
30  * @author Rene Scherer - Initial Contribution
31  */
32 @NonNullByDefault
33 public class SurePetcareHouseholdHandler extends SurePetcareBaseObjectHandler {
34
35     private final Logger logger = LoggerFactory.getLogger(SurePetcareHouseholdHandler.class);
36
37     public SurePetcareHouseholdHandler(Thing thing, SurePetcareAPIHelper petcareAPI) {
38         super(thing, petcareAPI);
39     }
40
41     @Override
42     protected void updateThing() {
43         SurePetcareHousehold household = petcareAPI.getHousehold(thing.getUID().getId());
44         if (household != null) {
45             logger.debug("Updating all thing channels for household : {}", household);
46             updateState(HOUSEHOLD_CHANNEL_ID, new DecimalType(household.id));
47             updateState(HOUSEHOLD_CHANNEL_NAME, new StringType(household.name));
48             updateState(HOUSEHOLD_CHANNEL_TIMEZONE_ID, new DecimalType(household.timezoneId));
49         } else {
50             logger.debug("Trying to update unknown household: {}", thing.getUID().getId());
51         }
52     }
53 }