ESPHome, emporia vue, winter, 2025

We had a incredible snowy winter this year in Toronto. 25cm of snow in 24 hours on Sunday [2025-02-16 Sun], which preceded by 20+cm earlier Thursday. While stuck at home, I found sometime to work on some long delaying projects. This got me into ESPHome. Yeah, home automation, somehow I feel this is probably inevitable for north American dwellers.

This days, the smart home word is incredibly messy, on the one hand, you have those giant players like Google home, Apple HomeKit, and Amazon Alexa. On the other hand, all the IoT manufactures are trying to steal user data by their crappy app. water valves, light switch, garage door openers. All of them are trying to lock you to their app. For you to simply close your garage, you have to send a command on your phone to their proprietary cloud server, then travel all the way back to connect to your opener at home. This is insane! Hopefully with the new Matter standard, it may bring some sanity back.

Event bus implementation, Part II, on a task system

Recap on EBus

From our last post on an eBus implementation. We talk about that how you can implement the Observer pattern so your can decouple the code from the callers to its callees. The perfect use case for that is obviously to register the observers for certain events such as ticks,

For example, a keyboard event listener may looks like this:

  //the listener will override those methods
  struct keyboard_input_listener : public ebus_handler<keyboard_events>
  {
          virtual void on_enter(keyboard_t* keyboard,
                                surface_t* surf, uint32_t key) override;
          virtual void on_leave(keyboard_t* keyboard, surface_t *surf) override;
          virtual void on_key(keyboard_t* keyboard,
                              uint32_t key, uint32_t state) override;
          //other events ...
  };
  //then listen on the events.
  keyboard_input_listener listener;
  listener.connect();

  //certain point a system will trigger events
  ebus<keyboard_events>::event(&keyboard_events::on_enter, ...);
  ebus<keyboard_events>::event(&keyboard_events::on_key, ...);
  ///...
  ebus<keyboard_events>::event(&keyboard_events::on_leave, ...);

But actually the power of the eBus is far beyond this. On top of this system, we can build other system as well. In this post, we are going to build a (async) task system.

Customizing Hide-Show for CMake Mode in Emacs

customizing HideShow mode on Emacs is done by hs-special-modes-alist. There are 4 parts (actually 5, but we care mostly about the 3) of the equation. You can customize it for your mode with a list like this

  (MODE START END COMMENT-START FORWARD-SEXP-FUNC ADJUST-BEG-FUNC)

For example, the default definition of the hs-special-modes-alist looks like this:

  (defvar hs-special-modes-alist
    (mapcar #'purecopy
            '((c-mode "{" "}" "/[*/]" nil nil)
              (c-ts-mode "{" "}" "/[*/]" nil nil)
              (c++-mode "{" "}" "/[*/]" nil nil)
              (c++-ts-mode "{" "}" "/[*/]" nil nil)
              (bibtex-mode ("@\\S(*\\(\\s(\\)" 1))
              (java-mode "{" "}" "/[*/]" nil nil)
              (java-ts-mode "{" "}" "/[*/]" nil nil)
              (js-mode "{" "}" "/[*/]" nil)
              (js-ts-mode "{" "}" "/[*/]" nil)
              (mhtml-mode "{\\|<[^/>]*?" "}\\|</[^/>]*[^/]>" "<!--" mhtml-forward nil)
              ;; Add more support here.
              ))

The ingredients

START and END regular expression

This regular expression matches the beginning/end of the folding code. For C/C++ alike languages, this is as brackets "{", "}", etc. For some language lacks of any brackets/parenthesis like python, it is more difficult. Emacs' built-in python mode provided patch to support it:

Event bus implementation

Recently I open sourced a small C++ library called eBus(Event Bus), it came along separated from another project I was working on. The idea, or should I say the interface was not very original, I took the inspiration from a much more complicated Event Buses In O3DE. The goal is simple, providing an easy to use Observer pattern so your can decouple the code from the callers to its callees.

Instead of doing this:

Moving to Hugo, Aftermath

My blog is now back online, with brand new render engine Hugo. The URLs are totally different though. Not sure how web crawlers handling it right now.

After the migration, I did a few extra work for patching the hiccups. Fix the build warnings and adding new features.

The about page

In every blog you always have some pages that you do not want it be inside the blog list. By default Hugo will simply place everything on the “navigation list”. Even if I place it outside the blog folder. This is the list your template is calling .NextPage and .PrevPage. So initially I just give it a very old date, or simply removed the date, so it will appear as the last on the list. Obviously I will have to fix that.

Moving to Hugo

For a long time I’ve been wanting to Migrate my blog system from Pelican to Hugo. One reason is that I had enough with python virtual environment breaks every 3 months. Another motivation is obviously I would like to replace Python with Go in my life.

A long time ago I followed Go tutorial for getting started, surprised by its syntax tidiness and similarity to Python, and it is way faster. But soon I found out it would be one of this thing I learned for a weekend and forget all together, since I don’t have any projects I would use it actively. Now after one month of procrastination, I finally pieces ALMOST everything to reproduce my old blog. Time for a summary.

Belief or Cult

It’s been a while that I haven’t update the blogs. It is so easy to slack off on good habits. “Oh I will continue once I finish A B C”. We are all busy as hell, in the software world, you WORK, you WORK and you GO TO SLEEP. Like this one, I am always hoping to switch to Hugo, then I can continue writing the blog. The thing is, I never got the good weekend to do the switching. Weekends are really no for staying at home confronting monitors.

July 2021 Status Update

I am now back in Canada, quarantined again. There is much of internal struggle whether I should move back or stay in Shanghai? Working for tech company in Shanghai or many cities in China would be like endless crunching. Maybe I was not used to this high-paced lifestyle, long working hours. Didn’t like javascript either. It is a pity that I didn’t find a nicer job maybe opens to better opportunities. I was focusing on the development of Taiwins back then, well it is working now and I don’t develop it anymore. The June was pretty unproductive, ever since the ICL implant surgery I couldn’t use computers for long, even now it is painful to do so. At least I get more time reading books?

Back with Org Mode

If there is one thing I’d like to commit it must be the my time mangement improvements. For that purpose, Emacs Org-mode is the ultimate tool for programmers. I can keep my notes nicely and I can track my tasks/errands all together. But all my notes are stored in my linux box, I lose access to them once I am away. From that reason, I was always on-and-off with using org-mode due to the portability. We are not in the age doing everything with desktop anymore, more often I need to track my TODOs from cellphone as well.

Jan 2021 Status Update

Folks, the Magical year of 2020 is behind us, and it wasn’t a happy new chapter waiting us. Man, I still couldn’t believe, once per 100 years, why it was us who have to face the coronavirus. Now I take a good look of my 2020, I went from trying to submit a xcbcommon handling patch to weston to writing a full wayland compositor from scratch. It was not my plan!!! Taiwins should have being a rather simple application on top of the libweston, the so called “reference compositor “, but libweston cannot change keyboard layout once launching, nor it can support cloning output, there are new bugs when you digging deep. The worst is that it breaks the library into different shared modules, and changes lib location every release. It was like it really does not want to link to it. The codebase was old and long, it was difficult to make a change and really difficult to get libweston taking a patch. Then there is the wlroots. If it was released half year earlier Taiwins would probably sit on top of that. But, screw it. I am doing it myself.