-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
519 additions
and
338 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import esphome.codegen as cg | ||
from esphome.components import number | ||
import esphome.config_validation as cv | ||
from esphome.const import ( | ||
CONF_ID, | ||
ENTITY_CATEGORY_CONFIG, | ||
) | ||
from .. import CONF_TC_ID, TCBus, tc_bus_ns | ||
|
||
SerialNumberNumber = tc_bus_ns.class_("SerialNumberNumber", number.Number, cg.Component) | ||
VolumeHandsetNumber = tc_bus_ns.class_("VolumeHandsetNumber", number.Number, cg.Component) | ||
VolumeRingtoneNumber = tc_bus_ns.class_("VolumeRingtoneNumber", number.Number, cg.Component) | ||
|
||
CONF_SERIAL_NUMBER = "serial_number" | ||
CONF_VOLUME_HANDSET = "volume_handset" | ||
CONF_VOLUME_RINGTONE = "volume_ringtone" | ||
|
||
CONFIG_SCHEMA = cv.Schema( | ||
{ | ||
cv.GenerateID(CONF_TC_ID): cv.use_id(TCBus), | ||
cv.Optional(CONF_SERIAL_NUMBER): number.number_schema( | ||
SerialNumberNumber, | ||
entity_category=ENTITY_CATEGORY_CONFIG, | ||
), | ||
cv.Optional(CONF_VOLUME_HANDSET): number.number_schema( | ||
VolumeHandsetNumber, | ||
entity_category=ENTITY_CATEGORY_CONFIG, | ||
), | ||
cv.Optional(CONF_VOLUME_RINGTONE): number.number_schema( | ||
VolumeRingtoneNumber, | ||
entity_category=ENTITY_CATEGORY_CONFIG, | ||
), | ||
} | ||
) | ||
|
||
|
||
async def to_code(config): | ||
tc_bus_component = await cg.get_variable(config[CONF_TC_ID]) | ||
|
||
if serial_number := config.get(CONF_SERIAL_NUMBER): | ||
n = await number.new_number( | ||
serial_number, min_value=0, max_value=1048575, step=0 | ||
) | ||
await cg.register_parented(n, config[CONF_TC_ID]) | ||
cg.add(tc_bus_component.set_serial_number_number(n)) | ||
|
||
if volume_handset := config.get(CONF_VOLUME_HANDSET): | ||
n = await number.new_number( | ||
volume_handset, min_value=0, max_value=7, step=1 | ||
) | ||
await cg.register_parented(n, config[CONF_TC_ID]) | ||
cg.add(tc_bus_component.set_volume_handset_number(n)) | ||
|
||
if volume_ringtone := config.get(CONF_VOLUME_RINGTONE): | ||
n = await number.new_number( | ||
volume_ringtone, min_value=0, max_value=7, step=1 | ||
) | ||
await cg.register_parented(n, config[CONF_TC_ID]) | ||
cg.add(tc_bus_component.set_volume_ringtone_number(n)) |
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,13 @@ | ||
#include "serial_number_number.h" | ||
|
||
namespace esphome { | ||
namespace tc_bus { | ||
|
||
void SerialNumberNumber::control(float value) | ||
{ | ||
this->publish_state(value); | ||
this->parent_->set_serial_number(value); | ||
} | ||
|
||
} // namespace tc_bus | ||
} // namespace esphome |
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,18 @@ | ||
#pragma once | ||
|
||
#include "esphome/components/number/number.h" | ||
#include "../tc_bus.h" | ||
|
||
namespace esphome { | ||
namespace tc_bus { | ||
|
||
class SerialNumberNumber : public number::Number, public Parented<TCBusComponent> { | ||
public: | ||
SerialNumberNumber() = default; | ||
|
||
protected: | ||
void control(float value) override; | ||
}; | ||
|
||
} // namespace tc_bus | ||
} // namespace esphome |
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,13 @@ | ||
#include "volume_handset_number.h" | ||
|
||
namespace esphome { | ||
namespace tc_bus { | ||
|
||
void VolumeHandsetNumber::control(float value) | ||
{ | ||
this->publish_state(value); | ||
this->parent_->update_setting(SETTING_VOLUME_HANDSET, value, 0); | ||
} | ||
|
||
} // namespace tc_bus | ||
} // namespace esphome |
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,18 @@ | ||
#pragma once | ||
|
||
#include "esphome/components/number/number.h" | ||
#include "../tc_bus.h" | ||
|
||
namespace esphome { | ||
namespace tc_bus { | ||
|
||
class VolumeHandsetNumber : public number::Number, public Parented<TCBusComponent> { | ||
public: | ||
VolumeHandsetNumber() = default; | ||
|
||
protected: | ||
void control(float value) override; | ||
}; | ||
|
||
} // namespace tc_bus | ||
} // namespace esphome |
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,13 @@ | ||
#include "volume_ringtone_number.h" | ||
|
||
namespace esphome { | ||
namespace tc_bus { | ||
|
||
void VolumeRingtoneNumber::control(float value) | ||
{ | ||
this->publish_state(value); | ||
this->parent_->update_setting(SETTING_VOLUME_RINGTONE, value, 0); | ||
} | ||
|
||
} // namespace tc_bus | ||
} // namespace esphome |
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,18 @@ | ||
#pragma once | ||
|
||
#include "esphome/components/number/number.h" | ||
#include "../tc_bus.h" | ||
|
||
namespace esphome { | ||
namespace tc_bus { | ||
|
||
class VolumeRingtoneNumber : public number::Number, public Parented<TCBusComponent> { | ||
public: | ||
VolumeRingtoneNumber() = default; | ||
|
||
protected: | ||
void control(float value) override; | ||
}; | ||
|
||
} // namespace tc_bus | ||
} // namespace esphome |
Oops, something went wrong.