Skip to content

Commit

Permalink
Add cardGrid2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
olicooper committed May 4, 2024
1 parent 0194b78 commit 6d9531a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ There are many UI components missing and the [python build script](components/ns

Currently the following features work:
- Screensaver with time, date, weather and status icon display
- Support for `cardGrid`, `cardEntities`, `cardQR`, `cardAlarm`
- Support for `cardGrid`, `cardGrid2`, `cardEntities`, `cardQR`, `cardAlarm`
- Most entity types should display on cards. Lights, switches, sensors and scenes have been tested to work, with additional support for the `popupLight` and `popupTimer` pages.

There is currently no support for cards such as: `cardMedia`, `cardThermo`, `cardPower` etc. but these are planned for the future.
Expand Down
13 changes: 11 additions & 2 deletions components/nspanel_lovelace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def AUTO_LOAD():
CARD_GRID2="cardGrid2"
CARD_QR="cardQR"
CARD_ALARM="cardAlarm"
CARD_TYPE_OPTIONS = [CARD_ENTITIES, CARD_GRID, CARD_QR, CARD_ALARM]
CARD_TYPE_OPTIONS = [CARD_ENTITIES, CARD_GRID, CARD_GRID2, CARD_QR, CARD_ALARM]

CONF_CARD_QR_TEXT = "qr_text"
CONF_CARD_ALARM_ENTITY_ID = "alarm_entity_id"
Expand Down Expand Up @@ -297,6 +297,8 @@ def get_card_entities_length_limits(card_type: str, model: str = 'eu') -> list[i
return [1,4] if model in ['eu','us-l'] else [1,6]
if (card_type == CARD_GRID):
return [1,6]
if (card_type == CARD_GRID2):
return [1,8]
if (card_type == CARD_QR):
return [1,2]
return [0,0]
Expand Down Expand Up @@ -370,6 +372,9 @@ def validate_config(config):
CARD_GRID: SCHEMA_CARD_BASE.extend({
cv.Required(CONF_CARD_ENTITIES): cv.ensure_list(SCHEMA_CARD_ENTITY)
}),
CARD_GRID2: SCHEMA_CARD_BASE.extend({
cv.Required(CONF_CARD_ENTITIES): cv.ensure_list(SCHEMA_CARD_ENTITY)
}),
CARD_QR: SCHEMA_CARD_BASE.extend({
cv.Required(CONF_CARD_ENTITIES): cv.ensure_list(SCHEMA_CARD_ENTITY),
cv.Optional(CONF_CARD_QR_TEXT): cv.string_strict
Expand Down Expand Up @@ -415,7 +420,7 @@ def validate_config(config):
CONF_SCREENSAVER: ["nspanel_screensaver", Screensaver, PageType.screensaver, WeatherItem],
CARD_ENTITIES: ["nspanel_card_", EntitiesCard, PageType.cardEntities, EntitiesCardEntityItem],
CARD_GRID: ["nspanel_card_", GridCard, PageType.cardGrid, GridCardEntityItem],
# CARD_GRID2: ["nspanel_card_", GridCard2, PageType.cardGrid2, GridCardEntityItem],
CARD_GRID2: ["nspanel_card_", GridCard, PageType.cardGrid2, GridCardEntityItem],
CARD_QR: ["nspanel_card_", QRCard, PageType.cardQR, EntitiesCardEntityItem],
CARD_ALARM: ["nspanel_card_", AlarmCard, PageType.cardAlarm, AlarmButtonItem]
}
Expand Down Expand Up @@ -690,6 +695,10 @@ async def to_code(config):
f"{nspanel.create_page.template(page_info[1]).__call__(card_uuids[i], title, sleep_timeout)}"))
# cg.add(cg.variable(card_variable, make_shared.template(page_info[1]).__call__(cg.global_ns.class_(page_info[0] + str(i + 1)))))

# Special case for pages which use a different underlying type
if card_config[CONF_CARD_TYPE] == CARD_GRID2:
cg.add(card_class.set_render_type(page_info[2]))

if card_config[CONF_CARD_HIDDEN] == True:
cg.add(card_class.set_hidden(True))
home_uuid = screensaver_uuid
Expand Down
2 changes: 1 addition & 1 deletion components/nspanel_lovelace/nspanel_lovelace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ void NSPanelLovelace::render_current_page_() {

this->command_buffer_.assign("pageType")
.append(1, SEPARATOR)
.append(this->current_page_->get_type_str());
.append(this->current_page_->get_render_type_str());
this->send_buffered_command_();
this->popup_page_current_uuid_.clear();

Expand Down
26 changes: 18 additions & 8 deletions components/nspanel_lovelace/page_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,30 @@ namespace nspanel_lovelace {
*/

Page::Page() :
uuid_(""), type_(page_type::unknown), hidden_(false),
uuid_(""), type_(page_type::unknown),
render_type_(page_type::unknown), hidden_(false),
sleep_timeout_(DEFAULT_SLEEP_TIMEOUT_S) {}

Page::Page(page_type type, const std::string &uuid) :
uuid_(uuid), type_(type), hidden_(false),
sleep_timeout_(DEFAULT_SLEEP_TIMEOUT_S) {}
uuid_(uuid), type_(type), render_type_(type),
hidden_(false), sleep_timeout_(DEFAULT_SLEEP_TIMEOUT_S) {}

Page::Page(
page_type type, const std::string &uuid, const std::string &title) :
uuid_(uuid),
type_(type), title_(title), hidden_(false),
uuid_(uuid), type_(type), render_type_(type),
title_(title), hidden_(false),
sleep_timeout_(DEFAULT_SLEEP_TIMEOUT_S) {}

Page::Page(
page_type type, const std::string &uuid, const std::string &title,
const uint16_t sleep_timeout) :
uuid_(uuid),
type_(type), title_(title), hidden_(false), sleep_timeout_(sleep_timeout) {}
uuid_(uuid), type_(type), render_type_(type),
title_(title), hidden_(false), sleep_timeout_(sleep_timeout) {}

// Copy constructor overridden so the uuid is cleared
Page::Page(const Page &other) :
uuid_(""), type_(other.type_), title_(other.title_), hidden_(other.hidden_),
uuid_(""), type_(other.type_), render_type_(other.render_type_),
title_(other.title_), hidden_(other.hidden_),
sleep_timeout_(other.sleep_timeout_) {}

void Page::accept(PageVisitor& visitor) { visitor.visit(*this); }
Expand All @@ -41,6 +43,14 @@ bool Page::is_type(page_type type) const {
return this->type_ == type;
}

const char *Page::get_render_type_str() const {
return to_string(this->render_type_);
}

void Page::set_render_type(page_type type) {
this->render_type_ = type;
}

void Page::set_items_render_invalid() {
for (auto &i : this->items_) {
i.get()->set_render_invalid();
Expand Down
4 changes: 3 additions & 1 deletion components/nspanel_lovelace/page_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class Page {
const std::string &get_uuid() const { return this->uuid_; }
const std::string &get_title() const { return this->title_; }
bool is_type(page_type type) const;
const char *get_type_str() const { return to_string(this->type_); }
const char *get_render_type_str() const;
void set_render_type(page_type type);
bool is_hidden() const { return this->hidden_; }
uint16_t get_sleep_timeout() const { return this->sleep_timeout_; }

Expand Down Expand Up @@ -75,6 +76,7 @@ class Page {

std::string uuid_;
page_type type_;
page_type render_type_;
std::string title_;
bool hidden_;
uint16_t sleep_timeout_;
Expand Down

0 comments on commit 6d9531a

Please sign in to comment.