mirror of
https://github.com/esphome/esphome.git
synced 2024-11-14 02:58:11 +01:00
Fix some binary_sensor not having an initial state (#819)
Fixes https://github.com/home-assistant/home-assistant/issues/28384
This commit is contained in:
parent
469c0db981
commit
70faeb2fa8
7 changed files with 13 additions and 7 deletions
|
@ -23,6 +23,7 @@ IS_PLATFORM_COMPONENT = True
|
||||||
|
|
||||||
binary_sensor_ns = cg.esphome_ns.namespace('binary_sensor')
|
binary_sensor_ns = cg.esphome_ns.namespace('binary_sensor')
|
||||||
BinarySensor = binary_sensor_ns.class_('BinarySensor', cg.Nameable)
|
BinarySensor = binary_sensor_ns.class_('BinarySensor', cg.Nameable)
|
||||||
|
BinarySensorInitiallyOff = binary_sensor_ns.class_('BinarySensorInitiallyOff', BinarySensor)
|
||||||
BinarySensorPtr = BinarySensor.operator('ptr')
|
BinarySensorPtr = BinarySensor.operator('ptr')
|
||||||
|
|
||||||
# Triggers
|
# Triggers
|
||||||
|
|
|
@ -67,7 +67,7 @@ class BinarySensor : public Nameable {
|
||||||
void send_state_internal(bool state, bool is_initial);
|
void send_state_internal(bool state, bool is_initial);
|
||||||
|
|
||||||
/// Return whether this binary sensor has outputted a state.
|
/// Return whether this binary sensor has outputted a state.
|
||||||
bool has_state() const;
|
virtual bool has_state() const;
|
||||||
|
|
||||||
virtual bool is_status_binary_sensor() const;
|
virtual bool is_status_binary_sensor() const;
|
||||||
|
|
||||||
|
@ -86,5 +86,10 @@ class BinarySensor : public Nameable {
|
||||||
Deduplicator<bool> publish_dedup_;
|
Deduplicator<bool> publish_dedup_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class BinarySensorInitiallyOff : public BinarySensor {
|
||||||
|
public:
|
||||||
|
bool has_state() const override { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace binary_sensor
|
} // namespace binary_sensor
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace ble_presence {
|
namespace ble_presence {
|
||||||
|
|
||||||
class BLEPresenceDevice : public binary_sensor::BinarySensor,
|
class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff,
|
||||||
public esp32_ble_tracker::ESPBTDeviceListener,
|
public esp32_ble_tracker::ESPBTDeviceListener,
|
||||||
public Component {
|
public Component {
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -394,7 +394,7 @@ class Nextion : public PollingComponent, public uart::UARTDevice {
|
||||||
bool wait_for_ack_{true};
|
bool wait_for_ack_{true};
|
||||||
};
|
};
|
||||||
|
|
||||||
class NextionTouchComponent : public binary_sensor::BinarySensor {
|
class NextionTouchComponent : public binary_sensor::BinarySensorInitiallyOff {
|
||||||
public:
|
public:
|
||||||
void set_page_id(uint8_t page_id) { page_id_ = page_id; }
|
void set_page_id(uint8_t page_id) { page_id_ = page_id; }
|
||||||
void set_component_id(uint8_t component_id) { component_id_ = component_id; }
|
void set_component_id(uint8_t component_id) { component_id_ = component_id; }
|
||||||
|
|
|
@ -28,7 +28,7 @@ class RDM6300Component : public Component, public uart::UARTDevice {
|
||||||
uint32_t last_id_{0};
|
uint32_t last_id_{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
class RDM6300BinarySensor : public binary_sensor::BinarySensor {
|
class RDM6300BinarySensor : public binary_sensor::BinarySensorInitiallyOff {
|
||||||
public:
|
public:
|
||||||
void set_id(uint32_t id) { id_ = id; }
|
void set_id(uint32_t id) { id_ = id; }
|
||||||
|
|
||||||
|
|
|
@ -267,11 +267,11 @@ class RemoteReceiverBase : public RemoteComponentBase {
|
||||||
uint8_t tolerance_{25};
|
uint8_t tolerance_{25};
|
||||||
};
|
};
|
||||||
|
|
||||||
class RemoteReceiverBinarySensorBase : public binary_sensor::BinarySensor,
|
class RemoteReceiverBinarySensorBase : public binary_sensor::BinarySensorInitiallyOff,
|
||||||
public Component,
|
public Component,
|
||||||
public RemoteReceiverListener {
|
public RemoteReceiverListener {
|
||||||
public:
|
public:
|
||||||
explicit RemoteReceiverBinarySensorBase() : BinarySensor() {}
|
explicit RemoteReceiverBinarySensorBase() : BinarySensorInitiallyOff() {}
|
||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
virtual bool matches(RemoteReceiveData src) = 0;
|
virtual bool matches(RemoteReceiveData src) = 0;
|
||||||
bool on_receive(RemoteReceiveData src) override {
|
bool on_receive(RemoteReceiveData src) override {
|
||||||
|
|
|
@ -30,7 +30,7 @@ void StatusBinarySensor::loop() {
|
||||||
|
|
||||||
this->publish_state(status);
|
this->publish_state(status);
|
||||||
}
|
}
|
||||||
void StatusBinarySensor::setup() { this->publish_state(false); }
|
void StatusBinarySensor::setup() { this->publish_initial_state(false); }
|
||||||
void StatusBinarySensor::dump_config() { LOG_BINARY_SENSOR("", "Status Binary Sensor", this); }
|
void StatusBinarySensor::dump_config() { LOG_BINARY_SENSOR("", "Status Binary Sensor", this); }
|
||||||
|
|
||||||
} // namespace status
|
} // namespace status
|
||||||
|
|
Loading…
Reference in a new issue