-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement carbon dioxide and monoxide sensors (#1210)
- Loading branch information
1 parent
cd1a7e0
commit 6492dd0
Showing
9 changed files
with
222 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "shelly_hap_carbon_dioxide_sensor.hpp" | ||
|
||
namespace shelly { | ||
namespace hap { | ||
|
||
CarbonDioxideSensor::CarbonDioxideSensor(int id, Input *in, | ||
struct mgos_config_in_sensor *cfg) | ||
: SensorBase(id, in, cfg, SHELLY_HAP_IID_BASE_CARBON_DIOXIDE_SENSOR, | ||
&kHAPServiceType_CarbonDioxideSensor, | ||
kHAPServiceDebugDescription_CarbonDioxideSensor) { | ||
} | ||
|
||
CarbonDioxideSensor::~CarbonDioxideSensor() { | ||
} | ||
|
||
Component::Type CarbonDioxideSensor::type() const { | ||
return Type::kCarbonDioxideSensor; | ||
} | ||
|
||
Status CarbonDioxideSensor::Init() { | ||
const Status &st = SensorBase::Init(); | ||
if (!st.ok()) return st; | ||
AddChar(new mgos::hap::UInt8Characteristic( | ||
svc_.iid + 2, &kHAPCharacteristicType_CarbonDioxideDetected, 0, 1, 1, | ||
std::bind(&mgos::hap::ReadUInt8<bool>, _1, _2, _3, &state_), | ||
true /* supports_notification */, nullptr /* write_handler */, | ||
kHAPCharacteristicDebugDescription_CarbonDioxideDetected)); | ||
return Status::OK(); | ||
} | ||
|
||
} // namespace hap | ||
} // namespace shelly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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_hap_sensor_base.hpp" | ||
|
||
namespace shelly { | ||
namespace hap { | ||
|
||
class CarbonDioxideSensor : public SensorBase { | ||
public: | ||
CarbonDioxideSensor(int id, Input *in, struct mgos_config_in_sensor *cfg); | ||
virtual ~CarbonDioxideSensor(); | ||
|
||
// Component interface impl. | ||
Status Init() override; | ||
virtual Type type() const override; | ||
}; | ||
|
||
} // namespace hap | ||
} // namespace shelly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "shelly_hap_carbon_monoxide_sensor.hpp" | ||
|
||
namespace shelly { | ||
namespace hap { | ||
|
||
CarbonMonoxideSensor::CarbonMonoxideSensor(int id, Input *in, | ||
struct mgos_config_in_sensor *cfg) | ||
: SensorBase(id, in, cfg, SHELLY_HAP_IID_BASE_CARBON_MONOXIDE_SENSOR, | ||
&kHAPServiceType_CarbonMonoxideSensor, | ||
kHAPServiceDebugDescription_CarbonMonoxideSensor) { | ||
} | ||
|
||
CarbonMonoxideSensor::~CarbonMonoxideSensor() { | ||
} | ||
|
||
Component::Type CarbonMonoxideSensor::type() const { | ||
return Type::kCarbonMonoxideSensor; | ||
} | ||
|
||
Status CarbonMonoxideSensor::Init() { | ||
const Status &st = SensorBase::Init(); | ||
if (!st.ok()) return st; | ||
AddChar(new mgos::hap::UInt8Characteristic( | ||
svc_.iid + 2, &kHAPCharacteristicType_CarbonMonoxideDetected, 0, 1, 1, | ||
std::bind(&mgos::hap::ReadUInt8<bool>, _1, _2, _3, &state_), | ||
true /* supports_notification */, nullptr /* write_handler */, | ||
kHAPCharacteristicDebugDescription_CarbonMonoxideDetected)); | ||
return Status::OK(); | ||
} | ||
|
||
} // namespace hap | ||
} // namespace shelly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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_hap_sensor_base.hpp" | ||
|
||
namespace shelly { | ||
namespace hap { | ||
|
||
class CarbonMonoxideSensor : public SensorBase { | ||
public: | ||
CarbonMonoxideSensor(int id, Input *in, struct mgos_config_in_sensor *cfg); | ||
virtual ~CarbonMonoxideSensor(); | ||
|
||
// Component interface impl. | ||
Status Init() override; | ||
virtual Type type() const override; | ||
}; | ||
|
||
} // namespace hap | ||
} // namespace shelly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters