-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartDevice.cpp
More file actions
109 lines (88 loc) · 2.89 KB
/
SmartDevice.cpp
File metadata and controls
109 lines (88 loc) · 2.89 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "SmartDevice.hpp"
#include "SmartDevice.hpp"
#include <ctime>
#include <iostream>
// Реализация SmartDevice
SmartDevice::SmartDevice(int id, std::string name, Status status)
: id_(id), name_(std::move(name)), status_(status) {}
int SmartDevice::getId() const { return id_; }
const std::string& SmartDevice::getName() const { return name_; }
SmartDevice::Status SmartDevice::getStatus() const { return status_; }
void SmartDevice::setStatus(Status status) { status_ = status; }
// Реализация ActiveDevice
ActiveDevice::ActiveDevice(int id, std::string name, Status status)
: SmartDevice(id, std::move(name), status), isActive_(false) {}
void ActiveDevice::activate() {
if (getStatus() == Status::ONLINE) {
isActive_ = true;
}
}
void ActiveDevice::deactivate() {
if (getStatus() == Status::ONLINE) {
isActive_ = false;
}
}
std::string ActiveDevice::getData() const {
return isActive_ ? "Active: ON" : "Active: OFF";
}
bool ActiveDevice::isActive() const { return isActive_; }
// Реализация SensorDevice
SensorDevice::SensorDevice(int id, std::string name, Status status)
: SmartDevice(id, std::move(name), status) {}
void SensorDevice::activate() {
// Датчики не имеют функции активации
}
void SensorDevice::deactivate() {
// Датчики не имеют функции деактивации
}
std::string SensorDevice::getData() const {
if (getStatus() != Status::ONLINE) {
return "OFFLINE";
}
if (getName().find("Temperature") != std::string::npos) {
return "Temperature: 22.5°C";
}
if (getName().find("Humidity") != std::string::npos) {
return "Humidity: 45%";
}
if (getName().find("Leak") != std::string::npos) {
return "Leak: No";
}
return "Sensor Data";
}
// Реализация HybridDevice
HybridDevice::HybridDevice(int id, std::string name, Status status)
: SmartDevice(id, name, status),
ActiveDevice(id, name, status),
SensorDevice(id, name, status),
isActive_(false) {}
void HybridDevice::activate() {
if (getStatus() == Status::ONLINE) {
isActive_ = true;
}
}
void HybridDevice::deactivate() {
if (getStatus() == Status::ONLINE) {
isActive_ = false;
}
}
std::string HybridDevice::getData() const {
if (getStatus() != Status::ONLINE) {
return "OFFLINE";
}
std::string activeStatus = isActive_ ? "Active: ON" : "Active: OFF";
std::string sensorData;
if (getName().find("Kettle") != std::string::npos) {
sensorData = "Temperature: 95°C";
}
else if (getName().find("Humidifier") != std::string::npos) {
sensorData = "Humidity: 60%";
}
else {
sensorData = "Hybrid Data";
}
return activeStatus + " | " + sensorData;
}
bool HybridDevice::isActive() const {
return isActive_;
}