[switch] Use C++17 nested namespace syntax (#14241)

This commit is contained in:
J. Nick Koston
2026-02-23 19:49:15 -06:00
committed by GitHub
parent 30cc51eac9
commit 843d06df3f
6 changed files with 16 additions and 28 deletions

View File

@@ -1,10 +1,8 @@
#include "automation.h"
#include "esphome/core/log.h"
namespace esphome {
namespace switch_ {
namespace esphome::switch_ {
static const char *const TAG = "switch.automation";
} // namespace switch_
} // namespace esphome
} // namespace esphome::switch_

View File

@@ -4,8 +4,7 @@
#include "esphome/core/automation.h"
#include "esphome/components/switch/switch.h"
namespace esphome {
namespace switch_ {
namespace esphome::switch_ {
template<typename... Ts> class TurnOnAction : public Action<Ts...> {
public:
@@ -104,5 +103,4 @@ template<typename... Ts> class SwitchPublishAction : public Action<Ts...> {
Switch *switch_;
};
} // namespace switch_
} // namespace esphome
} // namespace esphome::switch_

View File

@@ -1,8 +1,7 @@
#include "switch_binary_sensor.h"
#include "esphome/core/log.h"
namespace esphome {
namespace switch_ {
namespace esphome::switch_ {
static const char *const TAG = "switch.binary_sensor";
@@ -13,5 +12,4 @@ void SwitchBinarySensor::setup() {
void SwitchBinarySensor::dump_config() { LOG_BINARY_SENSOR("", "Switch Binary Sensor", this); }
} // namespace switch_
} // namespace esphome
} // namespace esphome::switch_

View File

@@ -4,8 +4,7 @@
#include "esphome/core/component.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
namespace esphome {
namespace switch_ {
namespace esphome::switch_ {
class SwitchBinarySensor : public binary_sensor::BinarySensor, public Component {
public:
@@ -17,5 +16,4 @@ class SwitchBinarySensor : public binary_sensor::BinarySensor, public Component
Switch *source_;
};
} // namespace switch_
} // namespace esphome
} // namespace esphome::switch_

View File

@@ -3,8 +3,7 @@
#include "esphome/core/controller_registry.h"
#include "esphome/core/log.h"
namespace esphome {
namespace switch_ {
namespace esphome::switch_ {
static const char *const TAG = "switch";
@@ -107,5 +106,4 @@ void log_switch(const char *tag, const char *prefix, const char *type, Switch *o
}
}
} // namespace switch_
} // namespace esphome
} // namespace esphome::switch_

View File

@@ -5,8 +5,7 @@
#include "esphome/core/helpers.h"
#include "esphome/core/preferences.h"
namespace esphome {
namespace switch_ {
namespace esphome::switch_ {
#define SUB_SWITCH(name) \
protected: \
@@ -16,10 +15,10 @@ namespace switch_ {
void set_##name##_switch(switch_::Switch *s) { this->name##_switch_ = s; }
// bit0: on/off. bit1: persistent. bit2: inverted. bit3: disabled
const int RESTORE_MODE_ON_MASK = 0x01;
const int RESTORE_MODE_PERSISTENT_MASK = 0x02;
const int RESTORE_MODE_INVERTED_MASK = 0x04;
const int RESTORE_MODE_DISABLED_MASK = 0x08;
constexpr int RESTORE_MODE_ON_MASK = 0x01;
constexpr int RESTORE_MODE_PERSISTENT_MASK = 0x02;
constexpr int RESTORE_MODE_INVERTED_MASK = 0x04;
constexpr int RESTORE_MODE_DISABLED_MASK = 0x08;
enum SwitchRestoreMode : uint8_t {
SWITCH_ALWAYS_OFF = !RESTORE_MODE_ON_MASK,
@@ -146,5 +145,4 @@ class Switch : public EntityBase, public EntityBase_DeviceClass {
#define LOG_SWITCH(prefix, type, obj) log_switch((TAG), (prefix), LOG_STR_LITERAL(type), (obj))
void log_switch(const char *tag, const char *prefix, const char *type, Switch *obj);
} // namespace switch_
} // namespace esphome
} // namespace esphome::switch_