Writing my first ESPHome component: Stuck at I2c communication

After recently getting a custom i2c component working as a “custom sensor” (see Custom Sensor Component — ESPHome) I would like to get my hand onto making it into a real ESPHome components, so others can use it as well.

The component I’m working with is a BQ27441 (as used on the battery babysitter: SparkFun Battery Babysitter - LiPo Battery Manager - PRT-13777 - SparkFun Electronics).

I’ve read the documentation on Contributing — ESPHome and got the basics working,
I now have a component that publishes some hard coded values.

The next step is to communicate with the actual sensor. I’ve been looking at the datasheet and at the sparkfun library.

The sparkfun library used the Wire library, I would have to re-write it to use the ESPHome i2c library.
The first thing the Sparkfun library does is a check if the right device is connected:

// Read the device type - should be 0x0421
uint16_t BQ27441::deviceType(void)
{
	return readControlWord(BQ27441_CONTROL_DEVICE_TYPE);
}

To do this, I have to send 2 bytes:

followed by another 2(?) bytes:

So that would basically be:
0x00 0x01 followed by 0x0001

Now the problem I have is that I don’t know what functions to use from the i2c library.
Should I use write_bytes 2x first and then read_bytes to get the response?

The documentation on ESPHome: esphome::i2c::I2CDevice Class Reference has this declariation:

 template<size_t N> bool write_bytes(uint8_t a_register, const std::array<uint8_t, N> &data) {
     return write_bytes(a_register, data.data(), data.size());
   }

What should be the value of a_register?

Got a little bit further. I believe a_register should be the address to write/read from.

The datasheet says:

All device writes (wr)and reads (rd) are implied to the I2C 8-bit addresses 0xAA and 0xAB, respectively

So I believe I need to do something like:

this->write_bytes(0xAA, {0x00, 0x01});
  this->write_bytes(0xAA, {0x0001});
  auto type_data = this->read_bytes<2>(0xAB);
 
  uint16_t type = 0;
  
  if (type_data.has_value()) {
    type = encode_uint16((*type_data)[0], (*type_data)[1]);
  }

  ESP_LOGW(TAG, "response: %d",  type);

However, it now prints : [W][bq27441:058]: response: 2127
The expected response would be 0x0421, which would be 1057 as a int