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:
Otto Winter 2019-10-31 21:03:57 +01:00 committed by GitHub
parent 80aaf66963
commit adf2a463fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 13 additions and 7 deletions

View file

@ -23,6 +23,7 @@ IS_PLATFORM_COMPONENT = True
binary_sensor_ns = cg.esphome_ns.namespace('binary_sensor')
BinarySensor = binary_sensor_ns.class_('BinarySensor', cg.Nameable)
BinarySensorInitiallyOff = binary_sensor_ns.class_('BinarySensorInitiallyOff', BinarySensor)
BinarySensorPtr = BinarySensor.operator('ptr')
# Triggers

View file

@ -67,7 +67,7 @@ class BinarySensor : public Nameable {
void send_state_internal(bool state, bool is_initial);
/// 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;
@ -86,5 +86,10 @@ class BinarySensor : public Nameable {
Deduplicator<bool> publish_dedup_;
};
class BinarySensorInitiallyOff : public BinarySensor {
public:
bool has_state() const override { return true; }
};
} // namespace binary_sensor
} // namespace esphome

View file

@ -9,7 +9,7 @@
namespace esphome {
namespace ble_presence {
class BLEPresenceDevice : public binary_sensor::BinarySensor,
class BLEPresenceDevice : public binary_sensor::BinarySensorInitiallyOff,
public esp32_ble_tracker::ESPBTDeviceListener,
public Component {
public:

View file

@ -394,7 +394,7 @@ class Nextion : public PollingComponent, public uart::UARTDevice {
bool wait_for_ack_{true};
};
class NextionTouchComponent : public binary_sensor::BinarySensor {
class NextionTouchComponent : public binary_sensor::BinarySensorInitiallyOff {
public:
void set_page_id(uint8_t page_id) { page_id_ = page_id; }
void set_component_id(uint8_t component_id) { component_id_ = component_id; }

View file

@ -28,7 +28,7 @@ class RDM6300Component : public Component, public uart::UARTDevice {
uint32_t last_id_{0};
};
class RDM6300BinarySensor : public binary_sensor::BinarySensor {
class RDM6300BinarySensor : public binary_sensor::BinarySensorInitiallyOff {
public:
void set_id(uint32_t id) { id_ = id; }

View file

@ -267,11 +267,11 @@ class RemoteReceiverBase : public RemoteComponentBase {
uint8_t tolerance_{25};
};
class RemoteReceiverBinarySensorBase : public binary_sensor::BinarySensor,
class RemoteReceiverBinarySensorBase : public binary_sensor::BinarySensorInitiallyOff,
public Component,
public RemoteReceiverListener {
public:
explicit RemoteReceiverBinarySensorBase() : BinarySensor() {}
explicit RemoteReceiverBinarySensorBase() : BinarySensorInitiallyOff() {}
void dump_config() override;
virtual bool matches(RemoteReceiveData src) = 0;
bool on_receive(RemoteReceiveData src) override {

View file

@ -30,7 +30,7 @@ void StatusBinarySensor::loop() {
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); }
} // namespace status