/
shelly_component.hpp
82 lines (70 loc) · 2.26 KB
/
shelly_component.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Copyright (c) Shelly-HomeKit Contributors
* All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "shelly_common.hpp"
namespace shelly {
class Component {
public:
// NB: Keep in sync with Component_Type in JS.
enum class Type {
kSwitch = 0,
kOutlet = 1,
kLock = 2,
kStatelessSwitch = 3,
kWindowCovering = 4,
kGarageDoorOpener = 5,
kDisabledInput = 6,
kMotionSensor = 7,
kOccupancySensor = 8,
kContactSensor = 9,
kDoorbell = 10,
kLightBulb = 11,
kTemperatureSensor = 12,
kLeakSensor = 13,
kSmokeSensor = 14,
kMax,
};
explicit Component(int id);
virtual ~Component();
int id() const;
// Complex initialization after construction.
virtual Status Init() = 0;
virtual Type type() const = 0;
virtual std::string name() const = 0;
// Short status snippet string.
virtual StatusOr<std::string> GetInfo() const = 0;
// Full JSON status for UI.
virtual StatusOr<std::string> GetInfoJSON() const = 0;
// Set configuration from UI.
virtual Status SetConfig(const std::string &config_json,
bool *restart_required) = 0;
// Set state from UI.
virtual Status SetState(const std::string &state_json) = 0;
// Do something to identify this component to the user.
// Default is to print a log message, which is to say - not much.
virtual void Identify();
// Is there any activity going on?
// If true is returned, it means it's ok to destroy the component.
// False should be returned if there is any user-visible activity,
// like curtain moving.
// Default implementation always returns true.
virtual bool IsIdle();
private:
const int id_;
Component(const Component &other) = delete;
};
} // namespace shelly